4 ms·
and Javascript uses promises and "then ()". What is "then ()"? Have they created their own wacky fork of Javascript? Javascript already handles asynchronous pr
by rwolf 15y ago
and Javascript uses promises and "then ()".
What is "then ()"? Have they created their own wacky fork of Javascript? Javascript already handles asynchronous programming (feel free to argue that is doesn't do it "right" or even "well"), so why extend the language?
- kevingadd 15y agoIt's a method with a signature like this: promise.then(callback) so: var p = doSomethingAsync(); p.then(function () { alert("hello"); })
- rwolf 15y agoI saw all of those extra spaces around "then" in the article and assumed the worst. Thanks for clearing that up for me!
- nxn 15y agoI'm assuming they only chose to use this pattern for the purpose of keeping function/method signatures as uniform across the languages as possible? I can't see another advantage to this in JS. Seems like all it's doing is wrapping the call to the actual async operation within the 'then' function, and then probably using the callback as the last argument or storing it somewhere where it will be accessible to the async operation right before it returns.
- IvoDankolov 15y agoFrom what I can tell it's just a convention in their APIs for binding continuations. You do some WinRT asynchronous call and pass a func to the then method to run when it completes. Nothing more than a onFinished event. No changes to async programming at all, events and continuations as always.