W3C home > Mailing lists > Public > public-script-coord@w3.org > January to March 2012

RE: variable declarations shadowing named properties on window

From: Travis Leithead <travis.leithead@microsoft.com>
Date: Fri, 6 Jan 2012 00:29:01 +0000
To: Ojan Vafai <ojan@chromium.org>, Cameron McCormack <cam@mcc.id.au>, Allen Wirfs-Brock <allen@wirfs-brock.com>
CC: Boris Zbarsky <bzbarsky@mit.edu>, "public-script-coord@w3.org" <public-script-coord@w3.org>, Ian Hickson <ian@hixie.ch>
Message-ID: <9768D477C67135458BF978A45BCF9B38381E7485@TK5EX14MBXW604.wingroup.windeploy.ntdev.microsoft.com>
Would love to hear Allen's take on this...

From: ojan@google.com [mailto:ojan@google.com] On Behalf Of Ojan Vafai
Sent: Thursday, January 05, 2012 3:36 PM
To: Cameron McCormack
Cc: Boris Zbarsky; Travis Leithead; public-script-coord@w3.org; Allen Wirfs-Brock; Ian Hickson
Subject: Re: variable declarations shadowing named properties on window

On Thu, Jan 5, 2012 at 3:14 PM, Cameron McCormack <cam@mcc.id.au<mailto:cam@mcc.id.au>> wrote:
Cameron McCormack:

Right, I don't think either of my proposals Travis quoted will work now,
due to this bareword lookup problem.

I might be a bit wrong here.  I forgot that [[HasProperty]] uses [[GetProperty]] to determine if there is a property on that object or on its prototype chain.  That means, if my reading of the spec is right, the following document

 <!DOCTYPE html>
 <script>var toString; alert(toString)</script>

should alert String(Object.prototype.toString) and not "undefined". Firefox, Opera and IE alert "undefined".  Chrome/Safari alert the function.

So I don't know that we can make `var something;` shadow any properties without violating the ECMAScript spec.

I haven't heard opposition to shadowing. It seems the only problem that's been brought up is figuring out how to spec it. Seems like an ES spec change is in order since a) it doesn't match what browsers do and b) shadowing is preferred in many cases.
Received on Friday, 6 January 2012 00:47:14 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:05 UTC