Simple, you need to use
this.status = val;
Otherwise you are just setting an unrelated global variable status
equal to val
.
And as already noted, setters/getters are not implemented in IE.
Also, I'm not sure about how wise it is to have a setter that is the same name as the property it sets. Not sure if this will result in a conflict, but it does seem like a bad idea yes? Ideally the variable that would be set should be hidden in a closure
var props = {
id: null,
title: null
};
(function() {
var status;
props.__defineSetter__("status", function(val){
//Checking correctness of val...
status = val;
});
props.__defineGetter__('status', function() { return status; });
}());
This way, status
is fully protected from direct access, which is the point of using setters and getters.