Scope is an enclosing context where values and expressions are associated. Use this tag for questions about different types of scope as well for questions where scope may be unclear.
Questions tagged [scope]
17524 questions
75
votes
3 answers
Static variables in C++
I would like to know what is the difference between static variables in a header file vs declared in a class. When static variable is declared in a header file is its scope limited to .h file or across all units. Also generally static variable is…

brett
- 5,379
- 12
- 43
- 48
75
votes
6 answers
Is there a performance difference between 'let' and 'var' in JavaScript
The difference between these two keywords in terms of scoping has already been thoroughly discussed here, but I was wondering if there is any kind of performance difference between the two, and if so, is it negligible, or at what point would it…

Nickolai
- 1,579
- 2
- 12
- 19
75
votes
2 answers
Access scope variables from a filter in AngularJS
I am passing date value to my custom filter this way:
angular.module('myapp').
filter('filterReceiptsForDate', function () {
return function (input, date) {
var out = _.filter(input, function (item) {
return…

Sergei Basharov
- 51,276
- 73
- 200
- 335
74
votes
8 answers
Controlling the value of 'this' in a jQuery event
I have created a 'control' using jQuery and used jQuery.extend to assist in making it as OO as possible.
During the initialisation of my control I wire up various click events like so
jQuery('#available input',
…

Pat Long - Munkii Yebee
- 3,592
- 2
- 34
- 68
74
votes
3 answers
What is the difference between variable_scope and name_scope?
What is the difference between variable_scope and name_scope? The variable scope tutorial talks about variable_scope implicitly opening name_scope. I also noticed that creating a variable in a name_scope automatically expands its name with the scope…

Andrzej Pronobis
- 33,828
- 17
- 76
- 92
74
votes
3 answers
How to force addition instead of concatenation in javascript
I'm trying to add all of the calorie contents in my javascript like this:
$(function() {
var data = [];
$( "#draggable1" ).draggable();
$( "#draggable2" ).draggable();
$( "#draggable3" ).draggable();
…

Maureen Moore
- 1,049
- 2
- 9
- 21
73
votes
7 answers
js: accessing scope of parent class
I have a jquery class within a normal class in javascript. Is it possible to access variables in the scope of the parent class from a callback function in the jquery class?
A simple example of what I mean is shown below
var simpleClass = function…

Sam
- 1,315
- 2
- 13
- 27
73
votes
6 answers
VB.Net Properties - Public Get, Private Set
I figured I would ask... but is there a way to have the Get part of a property available as public, but keep the set as private?
Otherwise I am thinking I need two properties or a property and a method, just figured this would be cleaner.

RiddlerDev
- 7,370
- 5
- 46
- 62
72
votes
8 answers
Can a Jinja variable's scope extend beyond in an inner block?
I have the following Jinja template:
{% set mybool = False %}
{% for thing in things %}
-
{% if current_user %}
{% if current_user.username == thing['created_by']['username'] %}
…

Matt Norris
- 8,596
- 14
- 59
- 90
72
votes
7 answers
How to use unscoped on associated relations in Rails3?
I have a default scope on products due to information security constraints.
class Product < ActiveRecord::Base
has_many :photos
default_scope where('visible = 1')
end
In my associated Photo model, however, I also have to find products that…

crispy
- 5,737
- 4
- 33
- 45
72
votes
4 answers
String with 'f' prefix in python-3.6
I'm trying out Python 3.6. Going through new code, I stumbled upon this new syntax:
f"My formatting string!"
It seems we can do things like this:
>>> name = "George"
>>> print(f"My cool string is called {name}.")
My cool string is called…

DevShark
- 8,558
- 9
- 32
- 56
72
votes
12 answers
How to remove elements/nodes from angular.js array
I am trying to remove elements from the array $scope.items so that items are removed in the view ng-repeat="item in items"
Just for demonstrative purposes here is some code:
for(i=0;i<$scope.items.length;i++){
if($scope.items[i].name == 'ted'){
…

TheNickyYo
- 2,389
- 5
- 20
- 28
72
votes
11 answers
How to inject variable into scope with a decorator?
[Disclaimer: there may be more pythonic ways of doing what I want to do, but I want to know how python's scoping works here]
I'm trying to find a way to make a decorator that does something like injecting a name into the scope of another function…

beardc
- 20,283
- 17
- 76
- 94
72
votes
4 answers
Why was block scope not originally implemented in JavaScript?
I have read, and discovered through my own experience, that JavaScript doesn't have a block scope. Assuming that the language was designed this way for a reason, can you explain to me what is that reason?
I've looked around on Google and here, but…

mricci
- 953
- 1
- 7
- 13
71
votes
3 answers
Why won't this compile without a default constructor?
I can do this:
#include
int counter;
int main()
{
struct Boo
{
Boo(int num)
{
++counter;
if (rand() % num < 7) Boo(8);
}
};
Boo(8);
return 0;
}
This will compile…

Zebrafish
- 11,682
- 3
- 43
- 119