getter and setter inheritance

Lars Hansen lhansen at adobe.com
Fri May 9 08:41:02 PDT 2008


Very timely questions.  I've been worrying about similar things this
week (more in the context of the ES4 type system) and not yet reached
any conclusions.
 
My view is that getters and setters introduce properties and that
whatever we do should be appropriate to that model.
 
Others seem to think that getters and setters introduce a way of
invoking normal methods by a different syntax and that they are truly
just methods.  In the world of classes and instances that may be
appropriate, but not in the object-and-property world of ES3, I expect.
 
--lars


________________________________

	From: es4-discuss-bounces at mozilla.org
[mailto:es4-discuss-bounces at mozilla.org] On Behalf Of Kris Zyp
	Sent: 9. mai 2008 07:19
	To: es3.x-discuss at mozilla.org; es4-discuss Discuss
	Subject: getter and setter inheritance
	
	
	A question of how inheritance/delegation should work with
getters and setters was raised in a recent discussion. If there is an
object A whose prototype is object B, and object A defines a getter for
property foo, and object B defines a setter for property foo, and we
write a value to A.foo, should the setter defined on object B be called?
If A didn't define any property on A, the setter would be inherited from
B and would be called when A.foo was modified. However, with the getter
defined on A, should the inheritance stop at A, because there is a slot
defined, or should it continue along the prototype chain because there
was no setter defined for that property (nor plain value)? The question
also applies when the getter and setter are reversed. When a property is
accessed and there is a setter defined, but no getter, should we
continue to down the prototype chain to find a getter or a plain value,
or stop and return undefined? AFAICT, ES4 doesn't explicitly define
which is the correct behavior. Firefox follows the former behavior:
	 
	B={set foo(v){foo = v},
	    get bar(){return "bar value"}}
	A={get foo(){return "foo value"},
	    set bar(v){bar = v},
	    __proto__:B}
	 
	A.bar -> undefined
	A.foo = 'new value' -> setter is not called, foo is not set
	 
	Thanks,
	Kris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20080509/2000f309/attachment-0002.html 


More information about the Es4-discuss mailing list