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
_______________________________________________
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss