Settings

Theme

Metaprogramming with ECMAScript 6 proxies

2ality.com

46 points by riccardoforina 11 years ago · 4 comments

Reader

AnkhMorporkian 11 years ago

This is huge.

        var proto = new Proxy({}, {
            get(target, propertyKey, receiver) {
            console.log('GET '+propertyKey);
            return target[propertyKey];
         }});
I've been following ES6 pretty closely, but somehow I missed this huge feature. Don't get me wrong, I love generators and destructuring, but this is soooo cool.
  • tracker1 11 years ago

    Should allow for the creation of a library to support Functional JS immutable instances...

  • Offler 11 years ago

    Getters have been in JS since ES5 and can do what you just wrote. Obv Proxy is more powerful/has more traps.

    • rauschma 11 years ago

      Not completely: with getters, you have to decide on a specific set of properties, the proxy GET trap intercepts all get operations. But I agree that you don’t always need proxies.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection