Questions tagged [scope-chain]
35 questions
0
votes
1 answer
javascript closure and scope chain example
Can someone explain to me (clearly and concisely) why this code works the way it does? I come from a strongly typed background in Java (6 and 7) where closures don't exist and do not function the way they do in javascript. I think the concepts…

HiChews123
- 1,598
- 4
- 20
- 39
0
votes
1 answer
Is it a way to capture the stack of closure definition?
I'm currently researching a way to protect JavaScript functions as private, exception will be thrown if the caller is invalid. Then I have a problem here: If a closure is defined inside a valid caller, is it a way to get the valid caller from the…

Knly
- 9
- 3
0
votes
2 answers
Writing scopes for many-to-many relationships
I've got an application with 3 models: Renters, Departments, Criteria.
# app/models/department.rb
class Department < ActiveRecord::Base
attr_accessible :name, :abbr
has_many :renter_departments
has_many :renters, :through =>…

Vidur
- 1,442
- 2
- 17
- 37
-1
votes
1 answer
How do block scopes have access to enclosing scope
i do understand that due to lexical scoping, block scopes can access the enclosing scope variables. But what i do not understand is how it really works.
ex:
function first(){
let i=10;
function second(){
let j=20;
console.log(i);
…

Manishpant
- 37
- 1
- 5
-1
votes
2 answers
Scope in Javascript objects
When I execute this code
f= function(){
let test= "hello";
let ret={
"test": "world",
"func": function(){
console.log(test);
}
}
return ret;
}
let check= f();
check.func()
I get output as "hello". But I am …

Krrish Raj
- 1,505
- 12
- 28