strawman for the := operator

Axel Rauschmayer axel at rauschma.de
Wed Aug 8 18:57:24 PDT 2012


>> 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.

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120809/fe4443c1/attachment.html>


More information about the es-discuss mailing list