Home > Web Front-end > JS Tutorial > What is the javascript then method?

What is the javascript then method?

coldplay.xixi
Release: 2021-03-31 11:42:57
Original
5102 people have browsed it

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)].

What is the javascript then method?

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);
Copy after login

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

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template