You need (need in the sense "having readable construct to perform") .{...} with [[DefineOwnProperty]] not for "foo":"bar" (yes, there [[Put]] should happen), but for dynamically adding concise methods and/or getters/setters to objects.

Using API is much more cumbersome here. And lots of bugs can appear if people will use .defineProperties instead of .defineMethod, for example. And object literal extension, because it has identical syntax, is super readable.

Not that I don't like the idea, by the way... but stopping literal extension is too much. Retain it in some way (like foo.={literal} or so).

Herby

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

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:

Bingo. The different between [[DefineOwnProperty]] and [[Put]] is subtle and 
rarely encountered when dealing with a new object.

The distinction between the two operations is a corner case of the language, 
and [[Put]] is the common case.

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.

I agree we should only be considering syntax for [[Put]] -- syntactic sugar 
should be to support common patterns, not to invent patterns that don't fit 
smoothly within the rest of the language.

However, I really, really oppose reusing syntax that's used for declarative 
data construction (i.e., literals) to notate *update* operations. We should not 
use the object literal notation for [[Put]]. We should use assignment syntax, 
which corresponds to doing assignment on an object.

This was the motivation between my blog post a while back on a different syntax 
for mustache:

     http://blog.mozilla.org/dherman/2011/12/01/now-thats-a-nice-stache/

tl;dr: instead of an object literal, the RHS of mustache should have a syntax 
that corresponds more closely to that of blocks. It allows assignments and 
method calls.

     array.{
         pop();
         pop();
         pop();
     };

     path.{
         moveTo(10, 10);
         stroke("red");
         fill("blue");
         ellipse(50, 50);
     };

     this.{
         foo = 17;
         bar = "hello";
         baz = true;
     };

(I'll eventually write up a new strawman for it, but I'm working on the new 
wiki right now which I consider higher priority.)

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

Reply via email to