with and scope chain augmentation

David-Sarah Hopwood david-sarah at jacaranda.org
Wed Jun 24 18:29:55 PDT 2009


Juriy Zaytsev wrote:
> In a nutshell, if one wanted to create a function object out of a string
> value of intrinsic event attribute, something along these lines would
> need to be used (for a more or less complete emulation):
> 
> function eventHandlerFromAttr(element, attrValue){
>   return function(e){
>     with(document){
>       with(element){
>         var fn = eval('(function(event){' + attrValue + '})');

This is eval'ing in the current lexical context. You want a global eval.
In ES5:

          var evil = eval;
          var fn = evil('(function(event){' + attrValue + '})');

>         return fn.call(element, e);
>       }
>     }
>   }
> }

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com



More information about the es-discuss mailing list