4 ms·
There is another nice feature of ES6 that helps a lot with callbacks and promises: proxies. Check out this article I wrote on Flippin Awesome (http://flippinawe
by porphyry3 13y ago
There is another nice feature of ES6 that helps a lot with callbacks and promises: proxies. Check out this article I wrote on Flippin Awesome (http://flippinawesome.org/2013/11/18/taming-asynchronous-javascript-programming-with-ecmascript6/ http://flippinawesome.org/2013/11/18/taming-asynchronous-jav...). The following is some sample code to show how code can be simplified with ES6 proxies, making async functions chainable (example in coffeescript):
getUser = (user) ->
_("https://npmjs.org/~#{user}")
.get()
.extractLinks()
.filter( -> /package/.test(arguments[0]) )
.map( -> "https://npmjs.org#{arguments[0]}" )
.log()
getUser("foo")
where `get` is THE jQuery get for Ajax requests returning a promise and is chained with the rest of the functions in a pipeline fashion. I've found that these techniques can work very well for form validation, as [you can check here](http://www.vittoriozaccaria.net/chained/demo.html http://www.vittoriozaccaria.net/chained/demo.html) — Firefox required.
Edit: I wrote in markdown but it seems that only verbatim is supported.
Edit2: some clarification