So I have learned that in Javascript we can use defineProperties to define multiple properties of object. I have therefore tried it in a simple code below but I am not quiet getting the result I wanted. It seems that the accessors is not working and I don't know why.
var book = {};
Object.defineProperties(book,{
_year: {
value: 2004 },
edition: {
value: 1},
year: {
get: function(){
this._year;},
set: function(value){
if(value>2004){
this._year = value;
this.edition = this.edition + value - 2004;
});
this.year = 2016;
alert(book.edition); //1 why??
}