Answer the question
In order to leave comments, you need to log in
Why does alert called with no arguments show the result?
Hello!
There is a promise with a .then handler that displays a dialog box with a fulfilled result:
let promise = new Promise(resolve => resolve('Done!')).then(result => alert(result)) // Done!
let promise = new Promise(resolve => resolve('Done!')).then(alert) // Done!
Answer the question
In order to leave comments, you need to log in
You pass a function to then anyway.
In the first case, this function:
result => alert(result)
In the second, it's simple: It's
alert
easier to get on the variables, it seems to me. If you pass the function from the first example to a variable and feed then, everything will work exactly the same:
const func = result => alert(result);
let promise = new Promise(resolve => resolve('Done!')).then(func) //Выполнится func
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question