Below are tests for getters and setters in various web browsers, and also using Object.defineProperty.
var lost = {
loc : "Island",
get location () {
return this.loc;
},
set location(val) {
this.loc = val;
}
};
lost.location = "Another island";
Result: FAILED
9.0+
2.0+
3.0+
1.0+
9.5+
function Lost () {
// Constructor
}
Lost.prototype = {
get location (){
return this.loc;
},
set location (val){
this.loc = val;
}
};
var lostIsland = new Lost();
lostIsland.location = "Somewhere in time";
Result: FAILED
2.0+
3.0+
1.0+
9.5+
HTMLElement.prototype.__defineGetter__("node", function () {
return this.nodeName;
});
Result: FAILED
HTMLElement.prototype.__defineGetter__("description", function () {
return this.desc;
});
HTMLElement.prototype.__defineSetter__("description", function (val) {
this.desc = val;
});
document.body.description = "Beautiful body";
Result: FAILED
2.0+
3.0+
1.0+
9.5+
var lost = {
loc : "Island"
};
Object.defineProperty(lost, "location", {
get : function () {
return this.loc;
},
set : function (val) {
this.loc = val;
}
});
lost.location = "Another island";
Result: FAILED
9.0+
4.0+
5.1.7+
5.0+
11.6+
Object.defineProperty(document.body, "description", {
get : function () {
return this.desc;
},
set : function (val) {
this.desc = val;
}
});
document.body.description = "Content container";
Result: FAILED
8.0+
4.0+
5.1.7+
5.0+
11.6+