Why Does Copying Eval Change Its Behaviour?
According to the rollupjs documentation: Simply 'copying' eval provides you with a function that does exactly the same thing, but which runs in the global scope rather than the lo
Solution 1:
Because the ECMAScript 5 language specification says that direct references to eval
will execute in the local scope, while indirect references will use the global scope.
A more English-friendly description can be found on MDN:
If you use the eval function indirectly, by invoking it via a reference other than eval, as of ECMAScript 5 it works in the global scope rather than the local scope. This means, for instance, that function declarations create global functions, and that the code being evaluated doesn't have access to local variables within the scope where it's being called.
Post a Comment for "Why Does Copying Eval Change Its Behaviour?"