javascript then method is executed asynchronously, that is, the internal program of [then()] is executed after the method before [.then()] is executed. This avoids problems such as data not being obtained. The syntax is [promise.then(onCompleted, onRejected)].
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
Thethen() method is executed asynchronously.
means: when the method before .then()
is executed, the program inside then() will be executed. This will avoid problems such as data not being obtained.
Grammar:
promise.then(onCompleted, onRejected);
4. Parameters
promise is required. Promise object.
onCompletedRequired. The fulfillment handler function to run when the promise completes successfully.
onRejectedOptional. Error handler function to run when the promise is rejected.
Example:
vstart() { super.start(); if (this.transport) { return this.transport.ready.then(() => { return this.clientSM.start(); }); } else { return Promise.reject("no transport attached"); } }
Related free learning recommendations: javascript video tutorial
The above is the detailed content of What is the javascript then method?. For more information, please follow other related articles on the PHP Chinese website!