- From: Boris Zbarsky <bzbarsky@MIT.EDU>
- Date: Thu, 03 Oct 2013 12:10:47 -0400
- To: Domenic Denicola <domenic@domenicdenicola.com>
- CC: "public-script-coord@w3.org" <public-script-coord@w3.org>
On 10/3/13 9:34 AM, Domenic Denicola wrote: > Oh! It's just like ES5 object literals. A getter without a setter means no setter. The answer is `undefined`. Note that I was asking about the other way around: a setter with no getter. I assume that's what you were talking about too. That doesn't work, then. Consider this testcase, which sets up this situation: var objWithGetter = { get x() { return this._x; } } var objWithSetter = Object.create( objWithGetter, { "x": { set: function(arg) { this._x = arg; } } } ); function MyConstructor() { this._x = 0; } MyConstructor.prototype = objWithSetter; var testObj = new MyConstructor(); print(testObj.x); testObj.x = 17; print(testObj.x); This prints "undefined" twice (as exspected, because the undefined getter on objWithSetter shadows the getter we really want), whereas the obvious desired behavior is to print 0 and then 17. The point being, this is not a useful way to have a common superclass that's immutable and has the getters and a subclass with the setters, because due to how accessor descriptors work in ES those setters end up shadowing the getters. :( -Boris
Received on Thursday, 3 October 2013 16:11:23 UTC