In what ways does the following "eval" regularity break?

Brendan Eich brendan at
Thu Oct 30 13:27:55 PDT 2008

On Oct 30, 2008, at 1:09 PM, Brendan Eich wrote:

> These bugs involved, e.g. Prototype (the JS library) and its  
> Ajax.Updater (with evalScripts set to true). The code in question  
> used Prototype's forEach. A javascript: URL reduction:
> javascript: (function xxx(){ ["var x"].forEach(eval); })();

Prototype (and older, I think we suggested this as a  
workaround) has

   evalScripts: function() {
     return this.extractScripts().map(function(script) { return  
eval(script) });

No indirect eval called from map, but the operator eval here does not  
depend on its environment at all (it can't, since neither function in  
which it nests has any formal parameters or other local bindings). It  
could be optimized nicely in ES1-3.


More information about the Es-discuss mailing list