I realy like the possibility to react to dynamic properties, like what you
can do with Proxies.
But Proxies are not the (my) perfect solution.


```
class items {
    constructor() {
        return new Proxy(this, {
            get(target, name) {
                if (name[0] === '$') return
target.getItem(name.substr(1)).value;
                return target[name];
            }
        });
    }
    getItem(id) {
        return this._item[id];
    }
}

myItems = new items(); // [1]
myItems.$1
```

[1] this direct returns a Proxy for the newly created Object, ok..
i can do "myItems.$3" instead of "myItems.getItem(4)";


but i can not act like this inside the Object, because i am not working
with the Proxy

```
class items {
    getItem3(){
        return this.$3;
    }
}
```

I have to do this instead...

```
class items {
    getItem3(){
        return this.getItem(3);
    }
}
```

What about something like getters and setters for the rest (undefined
properties)?

```
class items {
    get...(name){
        if (name[0] === '$') return this.getItem(name.substr(1)).value;
    }
    set...(name, value){
        // implement setter for unknown
    }
}
```


Maybe a stupid idea and certainly not thought through.
But what do you think?
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to