简体   繁体   English

未捕获的TypeError:undefined不是函数

[英]Uncaught TypeError: undefined is not a function

Below javascript snippet is giving error on .done statement. 下面的javascript代码段在.done语句中给出了错误。 Error is "Uncaught TypeError: undefined is not a function " Since we can use done with promise any idea why this error is coming? 错误是“未捕获的TypeError:未定义的函数”由于我们可以使用done与promise来解决为什么会出现此错误?

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");
                    });

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 有没有这样的方法done ,也没有fail的无极API中,只有thencatch对象级别: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Methods

Promise.prototype.then(onFulfilled, onRejected) 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,并返回解析为被调用处理程序的返回值的新promise。

Promise.prototype.catch(onRejected) 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. 将拒绝处理程序回调附加到Promise,如果调用了回调,则将新的Promise解析为回调的返回值;如果实现了Promise,则返回为其原始实现值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM