Can somebody please explain to me why this simple piece of code is not working?
var user = {
get name() {
return this.name;
},
set name(value) {
this.name = value;
}
};
user.name = 'David';
When I put this in the Firebug console in Firefox 21.0 it gives me this error:
InternalError: too much recursion
this.name = value;
Why? What is the proper way to define getters and setters in Javascript?