This article analyzes the usage of JavaScript accessor properties and shares them for everyone's reference. The specific analysis is as follows:
This is a bit like the meaning of the constructor, but the function is different, he can have two properties to establish an association, by modifying a property to change another property.
Copy Code code as follows:
var book = {
_year:2004,
Edition:1
};
Object.defineproperty (book, year), {
Get:function () {
return this._year;
},
Set:function (NewValue) {
if (NewValue > 2004) {
This._year + = newvalue;
This.edition + = newValue-2004;
}
}
});
Book.year = 2006;
Console.log (book.edition);
As can be seen from the example, modifying _year, the output value changes only year, but through set, the edition changes at the same time when the year is modified.
I hope this article will help you with your JavaScript programming.