where the resolve and reject variable or function is defined?

I study angualr ,and I find some code like this:

function asyncFunc() {

return new Promise((resolve, reject) => { // (A)
    setTimeout(() => resolve('DONE'), 100); // (B)
});

}

I want to know where the function resolve and reject is defined? in all the demo,the author has not defined the function.it must be defined somewhere in angular core library.How can I find the source code that defined the two function?

阅读 2.4k
3 个回答

Well firstly it has nothing to do with Angular. It is the Promise object, which is now implemented on most modern browsers. You can also use a polyfill or other similar implementations.

The Promise constructor takes a function and passes it two arguments. They are functions known as "resolve" and "reject". But you can name them whatever you like. In a nutshell, it is the parameters that are used inside a function.

新手上路,请多包涵

emmm 你可以先看一下ES6的语法Promise

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题