On 5/29/2012 9:45 AM, Brendan Eich wrote:
Note that the modern DOM and WebIDL are being spec'ed so typical DOM
accessors are on prototypes, so you can't "fix" the bug by using
[[Put]] only when the property is "own".
There really is a difference between assigning and defining in JS.
Assigning runs setters, even inherited ones. Defining overrides or
shadows. EIBTI.
Once again, I'm not debating whether there is or isn't a difference,
just whether or not that difference is perceivable to regular
developers. My theory is that it is not, and so you'll end up with a lot
of code that looks like this:
var element = document.getElementById("myDiv");
element.{
innerHTML: "Hello world!",
className: "enabled"
};
Going by the current definition, this code block would actually have no
effect because it would be defining new own properties rather than
assigning values to the existing prototype accessor properties. I cringe
at the thought of how long it would take most developers to figure out
that it is the colon that's the problem. IMHO, This code doesn't behave
as expected.
-N
/be
Thanks,
Nicholas
On 5/28/2012 2:27 PM, Allen Wirfs-Brock wrote:
On May 28, 2012, at 1:23 PM, Erik Arvidsson wrote:
On Mon, May 28, 2012 at 12:19 PM, Nicholas C. Zakas
<standa...@nczconsulting.com> wrote:
Is it intentional that the first example uses colons between the
property
and value while all others use the equals sign?
Yes this is intentional. We discussed this a bit at the F2F meeting
and we came up with the proposal to use = for [[Put]] and : for
[[DefineOwnProperty]]. Having a way to do [[Put]] is important because
it is common to want to trigger setters.
At added a clarification of this to the strawman....
For example:
class Monster {
set health(value) {
this.barColor = value< 10 ? 'red' : 'green';
this._health = value;
}
}
class GiantSpider extends Monster {
constructor() {
this.{
health = 100
}
}
}
If you use .{health: 100} then the setter would not be invoked and the
object would not be in a correct state. This example might be a bit
contrived but using [[DefineOwnProperty]] is not the right answer in a
lot of cases.
This is especially important for setting values of DOM node
properties which are generally implemented as accessor properties
(ie, getters/setters). That is why I used (thanks to dherman) a
DOM element in most of the example that use +.
Allen
--
___________________________
Nicholas C. Zakas
http://www.nczonline.net
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss