Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@softwaredoug
Last activeJuly 11, 2025 09:58
    • Star(15)You must be signed in to star a gist
    • Fork(3)You must be signed in to fork a gist

    Select an option

    Save softwaredoug/9044640 to your computer and use it in GitHub Desktop.
    varPromise=function(wrappedFn,wrappedThis){
    this.then=function(wrappedFn,wrappedThis){
    this.next=newPromise(wrappedFn,wrappedThis);
    returnthis.next;
    };
    this.run=function(){
    wrappedFn.promise=this;
    wrappedFn.apply(wrappedThis);
    };
    this.complete=function(){
    if(this.next){
    this.next.run();
    }
    };
    };
    Promise.create=function(func){
    if(func.hasOwnProperty('promise')){
    returnfunc.promise;
    }else{
    returnnewPromise();
    }
    };
    @peter-moon
    Copy link

    sample usage

    var foo = function() {
    var promise = Promise.create(foo)
    async.wait(function() {
    promise.complete();
    });
    return promise;
    }

    @dopatraman
    Copy link

    Doesnt work. Can you please provide a full example?

    foo = new Promise(function() {return [1,2,3,4];});foo()TypeError: object is not a function

    Also doesnt work:

    foo.then(function(i) {return i}).complete()

    Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

    [8]ページ先頭

    ©2009-2025 Movatter.jp