Allen Wirfs-Brock wrote:
targetObj.prop = value //assign a value to a single property
targetObj .= sourceObj //assign values from sourceObj properties to
corresponding targetObj properties
targetObj := sourceObj //define properties on targetObj that clone
properties of sourceObj
If we only defined := now, we could still define .= in the future. If we define .= now to mean
"define property" we don't have a good future alternative for "assign multiple
property values"
But .= does not connote "assign" rather than "define". You make the case
that := suggests "define" by reference to the : separating property name
from value in object literals, and that's helpful. There's no dot analog
for colon, however.
Indeed if sourceObj is an object literal, we'd have, e.g.,
targetObj .= {prop1: val1, prop2: val2}
and at least as many colons as dots.
The more I think about this, the more I doubt we can help people decide
between assignment and definition just by giving both short syntax. The
requirement to define rather than assign is independent of syntax at the
redefinition point, inherent in the object model being used.
Further, assignment via = will remain the most common case, and the
source of bugs to reduce by documentation and education, no matter the
syntax of the fix. In teaching people how to make the fix or avoid the
bug, you're right that short syntax can help, but it's not clear how
much. As Dave points out, that depends on how often the need for
define-not-assign arises.
I fear we're missing the opportunity to get into Object.update by
getting stuck on syntax. The ES5 APIs are too verbose but that doesn't
mean something like Object.extend should be left to libraries and not
built in, as JSON and Function.prototype.bind were in ES5.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss