A closure in JavaScript is like keeping a reference ( NOT a copy) to the scope at the point of function declaration, which in turn keeps a reference to its outer scope, and so on, all the way to the global object at the top of the scope chain.The new function cannot reference the local variables of the outer function. When you use new Function(…) (the Function constructor) inside a function, it does not close over its lexical environment: it closes over the global context instead.The text you eval can reference local variables of the function, and in the non-strict mode, you can even create new local variables by using eval('var foo = …'). ![]() ![]()
0 Comments
Leave a Reply. |