function a(x) {
//...
return { b: b(arguments) }
}
function b(x, args) {
// x = foo
// args[0] = bar
}
a("foo").b("bar");
How do I get this to work ?
Inside function b I want to access x from function a and x from function b after this call: a("foo").b("bar");
Since
b(arguments)will be called immediately,b(arguments)have to return a reference to a function for that to work. Something like this:Like this
b(arguments)will be called immediately, and the return will be a reference to a function. When you then call.b("bar"), the returned function reference will be called. That function is within the scope of function b, since it is declared within it, and therefor the arguments passed toawill be available.A working fiddle: http://jsfiddle.net/XcgwV/