D
DanYan
So I was doing some stuff in Javascript, and I want to get access to a
function's scope chain. As a simplified example of what I actually am
trying to do, suppose I have this:
function add(b) {
return function(a) {
return a + b;
};
}
var add3 = add(3);
assert(5 == add3(2));
I want to be able to define a function mul3() that executes in the
same context as bar. I want to do something like this:
function mul3() {
return a * b; // I realize that no b is in static scope here -
see below
}
mul3.scope = add3.scope;
assert(6 == mul3(2));
It doesn't appear that functions have a scope property. Is there any
way at all to do this? Is there any theoretically standards-compliant
way to do it? Thanks!
function's scope chain. As a simplified example of what I actually am
trying to do, suppose I have this:
function add(b) {
return function(a) {
return a + b;
};
}
var add3 = add(3);
assert(5 == add3(2));
I want to be able to define a function mul3() that executes in the
same context as bar. I want to do something like this:
function mul3() {
return a * b; // I realize that no b is in static scope here -
see below
}
mul3.scope = add3.scope;
assert(6 == mul3(2));
It doesn't appear that functions have a scope property. Is there any
way at all to do this? Is there any theoretically standards-compliant
way to do it? Thanks!