Sometimes, we want to get a representation of another variable, or get an
abstract representation of some other variables. In this case, we often use
getter/setter. But defining a getter/setter in current scope is complex.
Can we make adding a getter or setter to current scope easier like the
following example?
```js
var a = 2;
get b() {return a+1;}
b; //returns 3
```
If I want to do this using current syntax, I need to write the following:
```js
var a = 2;
Object.defineProperty(this, 'b', {get: function(){return a+1}});
b; //returns 3
```
It is much more complex than the syntax I advised above. My advice also
makes defining a getter/setter in current scope look like defining a
getter/setter in an object, which makes it easy to remember.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss