On Mon, May 28, 2012 at 12:19 PM, Nicholas C. Zakas
<[email protected]> 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.
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.
--
erik
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss