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
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
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
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
Object.defineProperty(document.body, "description", { get : function () { return this.desc; }, set : function (val) { this.desc = val; } }); document.body.description = "Content container";
Result: FAILED