简体   繁体   中英

Asynchronous chaining in Javascript

I have been trying to get a not so sophisticated solution to chaining and this is what I came up with: http://jsfiddle.net/mithun_daa/fEGsj/2/

It seems to work but when I have multiple calls to "myapp":

//call the success callback
$('#ph').text(window.myapp.doWork(true).success(onSuccess).error(onSuccess));
//call the error callback
$('#ph').text(window.myapp.doWork(false).success(onSuccess).error(onError));

the callback is immediately called. I am trying to find a vanilla JS solution. I know jQuery provides promises but I was just curious to see how I would do it in pure JS.

这个问题无处不在,有一个完整的社区可以解决它http://www.promisejs.org将被纳入未来的js版本。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM