3 ms·
Yes, the V8 compiler bails out of several optimizations if your function uses eval. You can see this in the profiler: functions which V8 wasn't able to optimiz
by curveship 12y ago
Yes, the V8 compiler bails out of several optimizations if your function uses eval. You can see this in the profiler: functions which V8 wasn't able to optimize will have an alert sign next to them, and if you click it, it'll tell you what the issue was.
- Udo 12y agoVery cool, thanks for clearing that up!
- anonymoushn 12y agoThis is a bit troublesome! function f() {var x = 99; return function(a,b) {return a(b)};} f()(eval, 'console.log(x);') ReferenceError: x is not defined function f() {var x = 99; return function(a,b) {return eval(b)};} f()(eval, 'console.log(x);') 99 undefined
- curveship 12y agoYep, this is as per spec: http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.2 http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.2 . "Indirect" calls to eval (i.e. assigning eval to another variable, like you did by passing it as a param) are evaluated in terms of the global environment. "Direct" calls, like in your second example, use the local environment.