In the new ECMAScript5, two new syntactic sugars have been added, and these two syntactic sugars are the same.
var obj = (function() { var num = ten; return {
get N () { return num; }, set N (v) { = v; } =Console.log (OBJ.N);
Get means to read a value, in fact the implementation of get and set is a function, note that these two methods can only be used in the object, the other need to: remove, previously we write object properties need to add a colon, using these two methods do not need to add.
N in the above code is not fixed, write casually.
What's the use?
You can also think of no use, it just provides a new way of writing, for example, we have previously obtained the value of the function is required to add (), with this we can and get an object of the same property.
It is also important to note that the set ignores the return value because set is only used to change a value, and return does not make much sense.
ECMAScript5 new object syntax sugar getter and setter