ES6 Proxy vs Getters & Setters



I just read about ES6 Proxy.
It sounds to me as it does the same what you can do with getters and setters.
Is Proxy in ES6 an alternative for getters and setters?


It’s similar, but it can do more. Getters and setters, for example, only work for a specific property that you need to setup beforehand. Proxy, on the other hand, can work for any arbitrary property assignment. It can also handle new calls, deleting properties, and a few other things too. Enough things that there is no ES5 equivalent so Proxy can’t be properly transpiled to support older browsers through things like Babel.


Thanks for the explanation. But I didn’t get the last sentence.
Are you saying that Proxy cannot be transpiled to support older browsers?


I thought so. Was that not clear? :wink:

Unsupported feature
Due to the limitations of ES5, Proxies cannot be transpiled or polyfilled. See support in various JavaScript engines.