strawman for the := operator

Rick Waldron waldron.rick at gmail.com
Wed Aug 8 19:59:23 PDT 2012


On Wed, Aug 8, 2012 at 9:57 PM, Axel Rauschmayer <axel at rauschma.de> wrote:

> The problem is that neither = nor Object.defineProperty can be used
> succinctly and reliably to shadow or override.
>
>
> OK, that's the real problem, thanks for making it clear -- sorry if I
> missed it before.
>
>
> I still find the difference between assigning and defining very subtle. I
> am still trying to fully wrap my head around it.
>

The best way to think about it is to think of how innerHTML works. If you
"define" a property called "innerHTML", it would pave over the existing
innerHTML and all of the semantics would be lost. When you "assign" to
elem.innerHTML, the accessor semantics handle updating the DOM with the
value given as the AssignmentExpression on RHS.

Hopefully that helps?


Rick



> Isn’t there a reverse danger, too? That people use define when they
> actually want to use assignment? They might, for example, use := and expect
> a setter to be called.
>
> What is the use case for overriding? Isn’t it usually when you copy one
> object to another (a.k.a. Object.update() or Object.assign())? There you
> see code such as:
>
> https://github.com/documentcloud/underscore/blob/master/underscore.js#L690
>
>   // Extend a given object with all the properties in passed-in object(s).
>   _.extend = function(obj) {
>     each(slice.call(arguments, 1), function(source) {
>       for (var prop in source) {
>         obj[prop] = source[prop];
>       }
>     });
>     return obj;
>   };
>
>
> Clearly, here it is wrong to use assignment, but one has not choice if one
> wants to be compatible with ES3.
>
> Isn’t the answer Object.update(), then? Or are there other common pitfalls?
>
>         --
> Dr. Axel Rauschmayer
> axel at rauschma.de
>
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120808/8821c218/attachment-0001.html>


More information about the es-discuss mailing list