Enable proxies in hosts

Is it possible to enable EnmaScript 6 Harmony Proxies in nodejs? If so, what are the pros and cons? And is there any documentation on how to use them? Thank!

+20
ecmascript-harmony
May 19 '12 at 14:11
source share
5 answers

Calling node using node --harmony-proxies should do the trick.

Pros: proxies are a very powerful feature when you really need them.

Cons: proxies are too powerful a feature when you don't need them (which should be the case in most cases). In addition, the implementation should still be considered experimental.

As for the documentation, all that atm really is is Harmony virtualization, in particular this page, which reflects the current proxy implementation in V8 (and therefore node):

http://wiki.ecmascript.org/doku.php?id=harmony:proxies

+20
May 19 '12 at 16:19
source share

I recommend harmony-reflect , which makes it easy, for example, to configure get / set traps:

UPDATE carefully, below - CoffeeScript

 require 'harmony-reflect' handler = get: ( target, name ) -> console.log 'get' name return target[ name ] set: ( target, name, value ) -> console.log 'set' name target[ '%is-clean' ] = no if value isnt target[ name ] if value is undefined then delete target[ name ] else target[ name ] = value return value clean = ( x ) -> x[ '%is-clean' ] = yes return x p = Proxy {}, handler p[ 'a' ] = 1 p[ 'b' ] = undefined console.log p[ 'a' ], p[ 'b' ] console.log "c" of p, p[ 'c' ] console.log p clean p p[ 'a' ] = 1 console.log p p[ 'a' ] = 42 console.log p 

the above code is insightful for doing "transparent save of an object" in JavaScript. using harmony-reflect , it becomes trivial to make sure that all get and set actions on the object are intercepted - in this demo we set the %is-clean attribute so that we can check if the members of the object have changed and we also delete the elements that were set to undefined.

+2
Sep 19 '13 at 16:15
source share

You can use pimped-proxy, which facilitates the implementation of proxies, simplifying declaration and compatibility with ES5. Unlike a native proxy, it can only determine proxy properties at creation time.

https://github.com/Boulangerie/pimped-proxy

+1
Dec 10 '16 at 9:08
source share

Proxy now available initially in versions of Node> 6.

+1
Mar 08 '17 at 21:16
source share

Harmony proxies will not work so well for nodejs because they efficiently execute synchronous calls to type functions. That is, you cannot implement a proxy method that is asynchronous.

See this GitHub repository for examples: https://github.com/mschwartz/SilkJS-Harmony

-10
Nov 08
source share



All Articles