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

What is the javascript then method?

coldplay.xixi
coldplay.xixiOriginal
2021-03-31 11:42:575113browse

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);

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!

Statement:
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