anand
anand

Reputation: 11309

Uncaught TypeError: undefined is not a function

Below javascript snippet is giving error on .done statement. Error is "Uncaught TypeError: undefined is not a function " Since we can use done with promise any idea why this error is coming?

var promise = new Promise(function(resolve,reject)
                {

                    if(true)
                    {
                        console.log("1");

                    }
                    else
                        console.log("2");


                });
    promise.then( function(data1) {

                     if(true)
                    {
                        console.log("3");
                    }

                    else
                       console.log("4");
                })
                .then( function(data2) {

                     if(true)
                    {
                        console.log("5");
                    }
                    else
                        console.log("6");

                })
               .done( 
                    function(response) {
                       console.log("done")
                    });
                .fail(
                    function() {
                        console.log("fail");
                    });

Upvotes: 1

Views: 4544

Answers (1)

pomeh
pomeh

Reputation: 4902

There is no such method done nor fail in the Promise API, only then and catch at the object level: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Methods

Promise.prototype.then(onFulfilled, onRejected)

Appends fulfillment and rejection handlers to the promise, and returns a new promise resolving to the return value of the called handler.

Promise.prototype.catch(onRejected)

Appends a rejection handler callback to the promise, and returns a new promise resolving to the return value of the callback if it is called, or to its original fulfillment value if the promise is instead fulfilled.

Upvotes: 1

Related Questions