Questions tagged [scope-chain]
35 questions
1
vote
0 answers
Immediate Parent function is absent from returned function's scope chain
I've been doing some research on the [[scope]] property of function object.[[scope]] should incorporate all the outer function's variable object in addition to global object.
Here, the innermost function which returns from the Inner function, should…

AL-zami
- 8,902
- 15
- 71
- 130
1
vote
2 answers
To which variable object statements inside with are bind?
function buildUrl() {
var qs = "?debug=true";
with(location){
var url = href + qs;
}
return url;
}
buildUrl(); // it will work. WHY?
I am working through a "Professional JavaScript for Web Developers" by N. Zakas, and I came across this…

Piotrek Hryciuk
- 785
- 10
- 23
1
vote
1 answer
Does any language (or debugging tool) have a build in function or method to print out the scope chains?
Does any language or debug tool have a way to print out the scope chain for examination, so as to look at the different situations of what a scope chain contains?

nonopolarity
- 146,324
- 131
- 460
- 740
1
vote
1 answer
Dynamically added object properties not being added in Javascript
Please bare bear with me, I'm very new to Javascript. I am pulling my hair out trying to figure out why this won't work. Keep in mind I come from a Java background. I have a function 'getCsvData' and I'm essentially trying to parse a CSV file and…

HiChews123
- 1,598
- 4
- 20
- 39
1
vote
1 answer
javascript closure rules and scope chain
The closure rule is: functions are executed using the scope chain that was in effect when they are defined.
In the setTimeout callback function below, x is not yet in scope at the time of definition. Therefore, the program should print undefined,…

cmutex
- 1,478
- 11
- 24
1
vote
1 answer
Double nesting a function-valued return stops from entering the double nested function
Trying to understand the scope chain and execution context stack articles from David Shariff's Blog, I've tried to understand closures here
function foo() {
var a = 'private variable';
return function bar() {
alert(a);
}
}
var…

Kamafeather
- 8,663
- 14
- 69
- 99
0
votes
0 answers
In with-statement, how can i use the inject scope at inner function
how can i get $self variable in this code
const $sys = {};
Object.defineProperty($sys, 'comp', {
get: function() {
console.log('====', $self)
}
});
with({ $self: 1 }) {
console.log($sys.comp);
}
with seems like only works on its scope,…
0
votes
3 answers
Return variables from one function to use in another with python
I don't know why this isn't working
from bs4 import *
import time
import pandas as pd
import pickle
import html5lib
from requests_html import HTMLSession
s = HTMLSession()
url = "https://cryptoli.st/lists/fixed-supply"
def get_data(url):
r…

Justin Benfit
- 423
- 3
- 11
0
votes
2 answers
Passing a callback function as a string while retaining the scope chain
For an iPad app using a UIWebView, I'm passing a callback function to the app in an URL:
function query(db, query, callback) {
var iframe = document.createElement("IFRAME");
// Filter comments from the callback (as this would break things).
…

TinkerTank
- 5,685
- 2
- 32
- 41
0
votes
0 answers
Differences between Scope Chain and Closure
According to scope chain inner functions can access to outer functions, but at the same time we are accessing outer function through closure, then what is difference? Can anyone explain differences between scope chain and closure? My version is that…

Leonardo
- 133
- 2
- 8
0
votes
2 answers
Where do invalid variables go when using JavaScript's with(){} statement?
When using JavaScript's with statement, where do variables that have invalid names go?
var o = {"@#$%":1,"test":2}
with(o){
console.log(test)
// Can't do this:
//console.log(@#$%)
// Was it not imported, or is it just…

ADJenks
- 2,973
- 27
- 38
0
votes
1 answer
How to order by an attribute of a parent for a polymorphic model in ActiveRecord?
I think I worded that correctly...
I have a model called asset which is polymorphic:
class Asset < ActiveRecord::Base
belongs_to :assetable, :polymorphic => true
...
end
I have a class level method that acts as a scope:
def self.some_scope
…

Tony
- 18,776
- 31
- 129
- 193
0
votes
1 answer
How javascript retains the outer function's execution context when an inner function is returned?
I'm reading these two blogs: execution context and scope chain published by David Shariff diving depth into javascript's execution context and scope chain concept.
One thing not clear to me after reading the above blogs is how javascript prevents a…

Aaron Shen
- 8,124
- 10
- 44
- 86
0
votes
1 answer
javascript manipulating values within the scope chain
I've been reading up on Javascript closures and scope chains, but I haven't seen anything about maniuplating variables from within the scope chain. Here's a similar type of scenario I'm running into:
function first() {
var a = [];
…

Thomas
- 2,356
- 7
- 23
- 59
0
votes
3 answers
Why do new invocations of this function create new scope chains and a new private variables?
If we have this basic function (and its closures):
function counter(){
var n = 0;
return {
count: function() {return n++},
reset: function() {n = 0}
};
}
Is this what's happening in memory? (basically a pointer to a…

Gerald LeRoy
- 1,227
- 2
- 11
- 17