On May 29, 2012, at 9:33 AM, Tab Atkins Jr. wrote:

> On Tue, May 29, 2012 at 9:26 AM, Nicholas C. Zakas
> <[email protected]> wrote:
>> Thanks for the clarifications. I understand wanting to make the distinction
>> from an implementer point of view,

It isn't really an implementation issue.  This concerns some of the core 
semantics of the language. Implementors have to implement those semantics no 
mater how inconvenient it might be.

>> I'm just not sure that developers make
>> the distinction between [[Put]] and [[DefineOwnProperty]] even using regular
>> object literals. Is there a reason that this:
>> 
>> var obj = {};
>> obj.{
>>    name: "JS"
>> };
>> 
>> Can't act the same as this:
>> 
>> var obj = {};
>> obj.name = "JS";
>> 
>> Wherein, if the property is already defined that acts as [[Put]] and
>> otherwise acts as [[DefineOwnProperty]]?
> 
> Same thoughts here.  Regular devs (like me!) only see
> [[DefineOwnProperty]] when creating a literal, and then there's no
> observable distinction between these two in normal circumstances:
> 
> var obj = { foo: bar }
> 
> var obj = {};
> obj.foo = bar;

But in fact, there is already such an observable difference, if the prototype 
of obj already has a property named  "foo".  In these simple examples, the 
prototype is is Object.prototype but it more general cases (especially if we 
have class declarations) the object that is being extend is arbitrary.

Some cases where it a difference:

Object.defineProperty(Object.prototype, "foo", {set: function(v) 
{console.log(v]"hello: ",v)}, configurable: true});

var obj = {foo: bar};  //creates a own data property on obj that is initialize 
to the value of var

var obj={};
obj.foo = bar;  //does not create a property, produces console output: "hello: 
"+bar

Object.defineProperty(Object.prototype, "foo", {value: "can't change me", 
writable: false, configurable: true});

var obj = {foo: bar}; //creates a own data property on obj that is initialize 
to the value of var

var obj={};
obj.foo = bar;  //does not create a property, because inherited property is 
read-only

(function() {"use strict"; obj.foo = bar;})(); //throws a ReferenceError

> 
> I don't think it's worth optimizing for the [[DefineOwnProperty]]
> case.  We should just use the standard "foo:bar" syntax, and have it
> invoke [[Put]] behavior.
> 
> As written, the strawman's attachment of the more natural "foo:bar"
> syntax for [[DefineOwnProperty]] is a footgun.

ES 5 defines "foo:bar" as meaning [[DefineOwnPropertuy]].  Prior to the 
standardization of getter/setter semantics in ES5 some implementation used 
[[Put]] for "foo:bar".  That was identified as a potentially (perhaps even 
actually) exploitable security issue.  The semantics of "foo:bar" within an 
object literal is not going to change back to [[Put]]

I'm seen many concerns raised about consistency within JS.  Having {foo:bar} 
and obj.{foo:bar}   behave inconsistently doesn't seem like a very good idea. 


Allen



> 
> ~TJ
> 

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to