3 ms·
It's a matter of timing. A callback function could be called immediately and you need to be ready for that, so you need to define the callback before passing it
by skybrian 13y ago
It's a matter of timing. A callback function could be called immediately and you need to be ready for that, so you need to define the callback before passing it in. With a promise, you can call the then() method after the function returns; if the value is ready earlier then it will automatically be cached until you pick it up. The looser requirements on timing result in better decoupling; like any other value, you can put the promise in an arbitrary data structure and pick it up any time later, or perhaps not at all.
If you want to do this with callbacks you'll need to implement a way to cache the value and the result will be equivalent to a promise.