As you know we can define getters and setters in JS using defineProperty(). I\'ve been stuck when trying to extend my class using defineProperty().
It seems to me, that when you defineProperties for prototype, all instances shares that properties. So the right variant could be
var User = (function(){
// constructor
function User(id, name){
this.id = id
this.name = name
Object.defineProperty(this, "name", {
get: function(){ return name },
set: function(new_value){
//Some business logic, upperCase, for example
new_value = new_value.toUpperCase();
name = new_value
}
})
}
return User;
})();