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?
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.