with and scope chain augmentation

Juriy Zaytsev kangax at gmail.com
Tue Jun 23 15:13:10 PDT 2009

On Jun 23, 2009, at 5:18 PM, Jason Orendorff wrote:

> On Mon, Jun 22, 2009 at 2:43 PM, Mike Wilson<mikewse at hotmail.com>  
> wrote:
>> I sympathize with the slide "Problem: Can't emulate
>> platform objects" (which is addressed by e g getter/setter
>> properties), but the removal of with(){} in ES5 strict mode
>> would mean it gets harder to emulate the scope chain
>> augmentation done by browsers?
> Actually, I think we do this by wrapping event handlers in something  
> like
> (function (event) { ... })
> so "with" is not involved.  In fact, surely everyone does something
> like this, as event handlers have to support stuff like "return
> false;".

Last time I checked, most of the browsers actually *still were  
augmenting scope* of event handlers as if by using "with". There's  
been some research on this subject first by Cornford, then by Garrett  
Smith. Most of it is documented at <http://jibbering.com/faq/names/event_handler.html 

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){
         var fn = eval('(function(event){' + attrValue + '})');
         return fn.call(element, e);


Juriy Zaytsev
Co-founder, BitSonnet, Corp.
Core developer, Prototype.js
kangax at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20090623/a3620ea3/attachment-0001.html>

More information about the es-discuss mailing list