Li Xiaolong schrieb:
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
You already can do that:
```js
var a = 2;
with({get b() { return a+1; }) {
b // 3
}
```
However, magic bindings (that do something else than variable assignment
and access) are a source of confusion and usually a bad idea.
Why not simply use a function `b()` that you can call? It's clear what
happens with that.
We hardly need a special syntax for getter/setter variables in lexical
scopes.
- Bergi
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss