Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the state of the promise object in es6

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "what is the state of promise objects in es6". The editor shows you the operation process through an actual case. The method of operation is simple, fast and practical. I hope this article "what is the state of promise objects in es6" can help you solve the problem.

Status: 1. The state of pending in progress, which is initialized, but there is no result in the process; 2. If fulfilled is successful, resolved status will trigger subsequent then callback functions; 3. Rejected failure status, rejected status will trigger subsequent catch callback functions.

This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.

What are the states of promise objects in es6

Three states

1.pending: there are no results in the process

2.resolved: success

3.rejected: failed

State change

1. Pending-> resolved

2. Pending-> rejected

The expression of state

Pending status does not trigger then and catch

The resolved status triggers subsequent then callback functions

The rejected status triggers subsequent catch callback functions

Then and catch change state

Then normally returns resolved, and returns rejected if an error is reported.

Catch normally returns resolved, and returns rejected if an error is reported.

Test questions

/ / the first question (the result will be printed out 1 minute 3 Returns the resolved status) Promise.resolve () .then (() = > {console.log (1) / / 1 resolved}) .catch (() = > {console.log (2)}) .then (() = > {console.log (3) / / 3 resolved}) / / the second question (the result will be printed out) 3) Promise.resolve (). Then (() = > {console.log (1) / / 1 throw new Error ("error1") / / rejected}). Catch () = > {console.log (2) / / 2 resolved}). Then (() = > {console.log (3) / / 3 resolved}) / / third question (the result will print out 1) Promise.resolve.then (() = > {console.log (1)) / / 1 throw new Error ("error1") / / rejected}) .catch (() = > {console.log (2) / / 2 resolved}) .catch (() = > {console.log (3)})

This is the end of the content about "what is the status of promise objects in es6". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report