Is it possible to access the original property value from a Javascript getter?
If not, are there other “modern” javascript techniques for achieving something similar?
That is, if I have code like this
o = {}
o.foo = "bar"
o.__defineGetter__("foo", function(){
//can I access the value "bar" here?
return "some other value";
});
Is it possible to access the value “bar” from within my getter function? Or does using __defineGetter__ blow away the property?
(Context: not a newbie developer, but I’ve been ignoring non-cross-browser Javascript for the past 4/5 years and I’m looking to catch up)
ECMAscript 262 edition 5 introduced the option for having getters and setters on objects officially defined by spec. You can setup those either directly on an object literal
or using
Object.defineProperty()However, the problem remains the same. Overwritting a property will irrepealable overwrite it. What you can do, is use the objects
prototype chainto gleam properties.