I feel like this would be easier handled as a subclass helper:
```
f
unction asProxy(traps={}, Class=function asProxy(){}) {
return class extends Class {
constructor() {
super(...arguments);
return new Proxy(this, traps);
}
}
}
class MyClass extends asProxy({ ... }) { ... }
class MyOtherClass extends asProxy({ ... }, MyClass) { ... }
```
- Matthew Robb
On Wed, Aug 23, 2017 at 11:08 AM, Vihan Bhargava <[email protected]> wrote:
> The `Proxy` class is great for classes however at the moment, the current
> syntax can be unwieldy:
>
> ```
> class MyClass {
> constructor() {
> return new Proxy(this, {
> get: function(target, name) {
> if (name in target) return target[name];
> // ... do something to determine property
> }
> });
> }
> }
> ```
>
> My proposal is to introduce a more idiomatic syntax for proxies in classes:
>
> ```
> class MyClass {
> constructor () { ... }
> get *(name) {
> // ... do something to determine property
> }
> }
> ```
>
> This already is much more clear than the above.
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss