Testing getters and setters, and Object.defineProperty - To index of all tests and compatibility tables

Below are tests for getters and setters in various web browsers, and also using Object.defineProperty.

Regular getters and setters

Object literal notation

var lost = {
	loc : "Island",
	get location () {
		return this.loc;
	},
	set location(val) {
		this.loc = val;
	}
};
lost.location = "Another island";

Result: FAILED

Works in:

Object notation

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

Works in:

On DOM elements

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

Works in:

Object.defineProperty

On Objects

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

Works in:

On DOM elements

Object.defineProperty(document.body, "description", {
	get : function () {
		return this.desc;
	},
	set : function (val) {
		this.desc = val;
	}
});
document.body.description = "Content container";

Result: FAILED

Works in: