Git Product home page Git Product logo

Comments (5)

azu avatar azu commented on August 25, 2024

Promise vs jQuery という趣旨にするならば、以下に書かれてるonRejectedの引数が異なるために起きる問題について触れておいたほうが実用的な話になると思う。

むしろ、Promiseと合わせて使うことができるよ、普通にやるとエラー情報が取れないケースがあるかもよ、その解決方法について

という感じのがあれば良い気がする。

from promises-book.

azu avatar azu commented on August 25, 2024

Promise.resolve と相性が良くない話

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+辺りの違いについて

from promises-book.

azu avatar azu commented on August 25, 2024

細かい違い(Deferredが実装次第で揺れてしまうため)が沢山あったり、
多分jQuery Deferredもちゃんと理解してる人はそこまで多くないので、書く内容のバランスが難しい気がする。

両方に詳しい人が書いてくれるのがベストかなーと思う所。

全部について触れるのは結構きつそうなので、ここだという所を一点ぐらいでいいかもしれないなー

from promises-book.

azu avatar azu commented on August 25, 2024

シンプルな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が解決したりできる。
(2度解決はpromise上に作ってるので普通にできない

from promises-book.

azu avatar azu commented on August 25, 2024

#15 でかなり簡略化したPromiseとDeferredの関係について書いた。

http://azu.github.io/promises-book/#_deferred_promise

一応閉じますが、かなりぼかした感じなのでより詳細なのも継続して受け付けていますー


from promises-book.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.