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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -