It seems that __defineSetter__ no longer works in firefox latest version. It works in Chrome.
do you know Any replacement function that does the same thing and also works in other browsers like IE, Opera,Safari?
It seems that __defineSetter__ no longer works in firefox latest version. It works in Chrome.
do you know Any replacement function that does the same thing and also works in other browsers like IE, Opera,Safari?
__defineGetter__ and __defineSetter__ are still in the latest Firefox and I don't believe there are plans to remove them in the short term. In the long term, ECMAScript 5 specifies a different form of getters and setters that will eventually make its way into all browsers.
Here is an example of ECMAScript 5 getters and setters. It currently works in IE 9, Chrome 5, Safari 5: see here for a compatibility table.
var o = {};
Object.defineProperty(o, "p", {
get: function() {
return "A property";
},
set: function(val) {
alert("Setting " + val + "!");
}
});
Edit
As requested, here's a working example of __defineGetter__ and __defineSetter__, equivalent to the ES5 code above:
var o = {};
o.__defineGetter__("p", function() {
return "A property";
});
o.__defineSetter__("p", function(val) {
alert("Setting " + val + "!");
});