node.js - Async fluent javascript (node) interface (using deferreds) -


what best way build fluent interface in javascript (node.js)

obj.function1().function2().function3(); 

where functions asynchronous methods?

there module called chainsaw, if possilble deferreds , promises (https://github.com/kriskowal/q)

upd: chain q.js

obj.function1().then(obj.function2)  //inside obj.function2 "this" context lost,  //and code broken  obj.function1().then(funciton(){   obj.function2() // <-- "this" context ok })  

deferred implementation allows close, invoke:

obj.function1().invoke('function2').invoke('function3'); 

when es6 proxies become reality, there plan allow same functionality code below

obj.function1().function2().function3(); 

but we're not there yet.

also worth noting in deferred promise object function equals promise.then. plain functions can chained as:

function1()(function2)(function3); 

i hope that's helpful


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -