4 ms·
Is something similar to this possible with ES6 proxies? It'd be nice to use a lot of these features outside classes, but since proxies are far harder to polyfil
by thomasfoster96 11y ago
Is something similar to this possible with ES6 proxies? It'd be nice to use a lot of these features outside classes, but since proxies are far harder to polyfill (indeed, I don't think anyone's some it yet) I've only seen then done with decorators within classes.
- piran 11y agoNo these aren't the same as proxies. ES7 has class decorators that can only be used on class methods.
- thomasfoster96 11y agoI know they're not the same, but I'd love to be able to use some of the thins I can use with decorators, but on plain objects.
- eltaco 11y agoYou can also use them on class declarations themselves and object literals - https://github.com/wycats/javascript-decorators#object-literal-method-declaration https://github.com/wycats/javascript-decorators#object-liter...
- mako-taco 11y agoes7 decorators can also be used on vanilla objects, not just classes.
- thomasfoster96 11y agoReally? Any tutorials/posts/examples of using them on plain objects anywhere?
- mako-taco 11y agoYeah, check some of the examples in the readme
- aikah 11y agoyou dont need proxies, here is how decorators work and how you can implement them yourself, without the syntactic sugar obviously https://github.com/wycats/javascript-decorators https://github.com/wycats/javascript-decorators Proxies are an entire different thing.
- nawitus 11y agoI once implemented type checking in ES5 as a proof-of-concept: https://github.com/panuhorsmalahti/typed-javascript https://github.com/panuhorsmalahti/typed-javascript