-
-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PromiseとDeferredの違い #11
Comments
Promise vs jQuery という趣旨にするならば、以下に書かれてる むしろ、Promiseと合わせて使うことができるよ、普通にやるとエラー情報が取れないケースがあるかもよ、その解決方法について という感じのがあれば良い気がする。 |
var jqDeferred = Promise.resolve($.ajax('http://example.com/whatever.json'));
jqDeferred.then(function(response, statusText, xhrObj) {
console.info("Success");
}, function(xhrObj, textStatus, err) {
console.error(arguments);
}); http://jsbin.com/ruzunena/1/edit jQueryとPromise/A+辺りの違いについて |
細かい違い(Deferredが実装次第で揺れてしまうため)が沢山あったり、 両方に詳しい人が書いてくれるのがベストかなーと思う所。 全部について触れるのは結構きつそうなので、ここだという所を一点ぐらいでいいかもしれないなー |
シンプルなDeferred top on Promiseの例 "use strict";
function Deferred() {
this.promise = new Promise(function (resolve, reject) {
this._resolve = resolve;
this._reject = reject;
}.bind(this));
}
Deferred.prototype.resolve = function (value) {
this._resolve.call(this.promise, value);
};
Deferred.prototype.reject = function (reason) {
this._reject.call(this.promise, reason);
};
var deferred = new Deferred();
var promise = deferred.promise;
promise.then(function (value) {
console.log(value);
}).catch(function(error){
console.error(error);
});
deferred.resolve("Fulfilled!!!!");
// promiseは既にFulfilledになってるので、これは呼ばれない(catchは呼ばれない)
deferred.reject("doesn't called"); http://jsbin.com/qumabane/3/edit 名前の通り、promiseオブジェクトの状態を後からdeferredが解決したりできる。 |
#15 でかなり簡略化したPromiseとDeferredの関係について書いた。 http://azu.github.io/promises-book/#_deferred_promise 一応閉じますが、かなりぼかした感じなのでより詳細なのも継続して受け付けていますー |
PromiseとDeferredの違いについて
Deferredは
Twisted -> MochiKit/Dojo -> Promises/A -> jQuery.Deferred
時系列適当…
Deferred ∋ Promise という関係は明確だけど、細かい仕様はPromise/A+とかみたいなのがないきがするから、イマイチDeferredと言われた時に何をしめすものなのか分からない。(たいていはjQeuryになるんだろうけど)
正直そこまで詳しくないし、あまり興味持ってないから寄稿して欲しい感じ…
The text was updated successfully, but these errors were encountered: