with and scope chain augmentation

Garrett Smith dhtmlkitchen at gmail.com
Wed Jun 24 14:46:19 PDT 2009


On Wed, Jun 24, 2009 at 2:42 PM, Garrett Smith<dhtmlkitchen at gmail.com> wrote:
> On Wed, Jun 24, 2009 at 12:02 PM, Brendan Eich<brendan at mozilla.com> wrote:
>> On Jun 24, 2009, at 11:38 AM, Mike Wilson wrote:
>>
>>> Jason Orendorff wrote:
>>>>
>>>> Eeuuurgh.  In that case, what David-Sarah said.
>>>
>>> What did he say?
>>
>> He said "don't do that", to paraphrase. Full quote:
>>
>> "The 'with' can be in non-strict code, which is perfectly
>> adequate for implementing a backward-compatible misfeature
>> (the peculiar scope chain of a DOM0 event handler)."
>>
>
> Isn't it funny how something that seems small can have such a large
> effect? This misfeature doesn't seem to have a good role or use cases.
> It seems a bit like the callable collections that MSIE started.
>
> If HTML 5 author(s) only had the hindsight to see the problems with
> their inventions. I don't expect much at this point.
>
>> The nested DOM object scopes for event handlers was something I did to allow
>> brevity in inline event handler code. On balance it was a mistake, but it
>> was so popular that the VXML spec actually goes nuts and reifies nested XML
>> tags as objects on the scope chain for its ES scripting model!
>>
>
> Chrome actually shows the source code for the onclick using "with".
>
> Taking that document linked,

[snip]

No, that was the wrong code. Example bookmarklet:
javascript:document.write("<xmp>",
Function.prototype.toString.call(document.getElementsByTagName("input")[1].onclick),"<\/xmp>");

Produces in chrome:

function onclick(evt) {
  with (this.ownerDocument ? this.ownerDocument : {}) {
    with (this.form ? this.form : {}) {
      with (this) {
        return (function(evt){
self.alert([title, files, focus == window.focus]);
     var e = event||window.event;
     if(e && e.preventDefault) e.preventDefault();e.returnValue = false;
}).call(this, evt);
      }
    }
  }
}

Garrett


More information about the es-discuss mailing list