Is it possible to enable EcmaScript 6 Harmony Proxies in nodejs? If so, what are the pros and cons? And is there any documentation on how to use them? Thanks !
相关问题
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- google-drive can't get push notifications
- How to reimport module with ES6 import
- Why is `node.js` dying when called from inside pyt
- How to verify laravel passport api token in node /
相关文章
- node连接远程oracle报错
- How can make folder with Firebase Cloud Functions
- @angular-cli install fails with deprecated request
- node.js modify file data stream?
- How to resolve hostname to an ip address in node j
- Transactionally writing files in Node.js
- Log to node console or debug during webpack build
- Get file created date in node
Proxy
is now available natively in Node versions >= 6.Invoking node with
node --harmony-proxies
should do the trick.Pros: proxies are a very powerful feature when you really need them.
Cons: proxies are a much too powerful feature when you don't need them (which should be most of the time). Also, the implementation should still be regarded experimental.
As for documentation, all there really is atm is the Harmony wiki, in particular this page, which reflects the current implementation of proxies in V8 (and thus node):
http://wiki.ecmascript.org/doku.php?id=harmony:proxies
You can use pimped-proxy which a lightweight implementation of proxies, making declaration easier and ES5 compatible. Unlike the native Proxy, it can only proxy properties known at creation time.
https://github.com/Boulangerie/pimped-proxy
i recommend harmony-reflect, which makes it easy to e.g. set up get/set traps:
UPDATE careful, below is CoffeeScript
the above is the inceptive code to do 'transparent object persistence' in JavaScript. using
harmony-reflect
, it becomes trivial to make it so that allget
andset
actions on an object get intercepted—in this demo, we set an%is-clean
attribute so we can test whether object members have been changed, and we also delete members that have been set to undefined.Harmony Proxies won't work all that well for nodejs because they're effectively synchronous type function calls. That is, you can't implement a proxy method that's async.
See this GitHub repository for examples: https://github.com/mschwartz/SilkJS-Harmony