var x = 1;
function fn() {
console.log(x);
}
function show(f){
var x = 2;
f();
}
show(fn);
fn() function should have access to its outer execution context show(), which x is define as 2.
var x = 1;
function fn() {
console.log(x);
}
function show(f){
var x = 2;
f();
}
show(fn);
fn() function should have access to its outer execution context show(), which x is define as 2.
No. f
is bound with the context as it was when f
was defined, that is, when x = 1
. If you want x = 2
, you need to define fn
inside of the show
function.