eval-ing a function, performance after being evaled
We all know that the code:
var ssum = function(a,b) { return a+b; }
is 开发者_StackOverflowexecuting faster than
eval("var esum = function(a,b) { return a+b; } ");
for many reasons.
what I want to know is that if a function which was created by eval-ing a string will perform worse than a if it had not been.
For the example above it means: will esum(1,1) slower than ssum(1,1) ?
I would like an answer which tells me if this depends on the browser implementation (and if so why) and if the performance depends on the variables referenced by the eval-ed function.
Many Thanks, Lx
Once the js code is evaled, its converted into javascript ("javascript native" or "compiled") code (In your case. This is not the case always because eval evaluates an expression and the result of which can be, say, a number).
After that, they are plain 'ol javascript objects (functions or otherwise). So there should be no difference between the two.
Even the ECMA-262 spec (section 10.4.2) does not talk about such a case.
精彩评论