JSFiddle - React, Tailwind, and code Playground
JavaScript
'use strict';
var book = {};
Object.defineProperties(book, {
originYear: {
value: 2004,
writable: false
},
_year: {
value: 2004,
writable: true
},
edition: {
value: 1
},
year : {
get: function() {
return this._year;
},
set: function(newValue) {
if(newValue > this.originYear) {
this._year = newValue;
this.edition += newValue - this.originYear;
}
}
}
});
book.year = 2006;
alert(book._year);