Angry, Sina Weibo also too pits, code snippets too troublesome.
Promise's introduction is not much to say.Several web sites:http://es6.ruanyifeng.com/#docs/promisehttp://www.html5rocks.com/zh/tutorials/es6/promises/Https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
Next look how to be pit.First of all, the reason for the pit, mainly is that jquery deferred object and promise
1. ConceptThe Promise object is used for asynchronous (Asynchronouss) computations, and a Promise object represents an operation that is not yet completed, but is expected to complete.2. Reason for the occurrence:1) If you need to send multiple requests through Ajax, and each request relies on the result returned by the last request as a parameter to continue the next request, then you need to write this co
First, prefaceIn order for the front end to return to heaven from the callback of the underworld, jQuery also introduced Promise the concept.Promiseis a more elegant abstraction of the code's asynchronous behavior, and with it, we can write asynchronous code just like we write synchronous code.jQuerystarted with version 1.5. CommonJS The PROMISE/A specification is a heavyweight scheme, but not strictly impl
Asynchronous programmingJavaScript asynchronous Programming, web2.0 times more popular programming, we usually code when more or less used, the most typical is asynchronous Ajax, send asynchronous request, binding callback function, request response after calling the specified callback function, not blocking the execution of other code. There are also methods like settimeout methods that perform callbacks asynchronously.
If you are not familiar with asynchronous programming, direct poke Ruan a
Http://www.tuicool.com/articles/MVnmamrOriginal http://blog.segmentfault.com/f2e/1190000000523676First, prefaceIn order for the front end to return to heaven from the callback of the underworld, jQuery also introduced Promise the concept.Promiseis a more elegant abstraction of the code's asynchronous behavior, and with it, we can write asynchronous code just like we write synchronous code.jQuerystarted with version 1.5. CommonJS The
Preface
have been trying to write an article on promise to sum up before the promise knowledge points, take advantage of the work of leisure, to make a summary. PS: This article is suitable for a certain JavaScript basic children's shoes reading. What is Promise
When it comes to JavaScript asynchronous processing, I think most people would think of using a callb
[ZT] How should the boss promise to core employees?
How should the boss promise to core employees?Author: Jing suqi 10:18:11Source: blog China (blogchina.com) Source: Chinese and Foreign Management b28123cThe flow of employees is normal, but the flow is also regular.Generally, most of the employees who left the company a year ago want to quit.Most of the company's core employees quit,Most of the departure
Meaning of the 1.Promise:Promise is a solution for asynchronous programming that is more logical and powerful than traditional solutions-callback functions and events. It was first proposed and implemented by the community, ES6 wrote it into the language standard, unified the usage, the native provided the Promise object.The so-called Promise simple is a container that holds the result of an event (usually
Promise represents an asynchronous operation that is not yet complete, but will be completed in the future.There are three states of Promise
Pending: Initial state, not yet known results
Fulfilled: Represents successful operation
Rejected: Representative operation failed
If the Promise operation is fulfilled or rejected, and the correspondin
Anyone who learns Android knows that Java is multi-threaded, and when it takes a time-consuming operation, such as requesting data from the server, it is often necessary to open a thread to execute it.But in our JS, is single-threaded, request network data, we can not determine when will return, if the network is not very good, then it will be very slow. So it is impossible to wait for his request to complete before going to the next steps. So we need
What is it?https://www.promisejs.org/
What is
a promise?
The core idea behind promises is, a promise represents the result of an asynchronous operation. A promise is in one of three different states:
Pending-the initial state of a promise.
Fulfilled-the State of a
In the ES6 syntax, a new promise constructor is created that can be used to generate promise instances.Promise object: Represents a future event that will occur (usually an asynchronous operation). With the Promise object, asynchronous operations can be expressed in a synchronous process, avoiding nested callback functions (commonly called ' callback hell ').In A
A popular alternative to building asynchronous APIs is to use promise (sometimes referred to as deferred or future) mode. Asynchronous APIs that have been discussed in this chapter use callback functions as parameters.downloadAsync(‘file.txt‘,function(file){ console.log(‘file:‘+file);});The Promise-based API does not receive callback functions as parameters. Instead, it returns a
The Promise object is a unified interface provided by the COMMONJS workgroup for asynchronous programming, which provides native support for promise in ECMASCRIPT6, and promise is what happens in the future, and using promise avoids the layer nesting of callback functions, It also provides the specification for easier
, success: function (data) { $.ajax ({ //...});});} );3. Consider this scenario, if we send two AJAX requests at the same time and then do one more thing after the two requests have been successfully returned, think about how difficult it is to attach the callback in the respective call location only in the previous way? You can see that asynchronous operations like Ajax in JavaScript lead to complex nesting levels, poor readability, and sometimes
Before we begin our formal presentation, we'd like to look at the JavaScript promise:
Copy Code code as follows:
var p = new Promise (function (resolve, reject) {
Resolve ("Hello World");
});
P.then (function (str) {
alert (str);
});
1. Then () returns a forked Promise
What is the difference between the following two paragraphs o
From C # to typescript-promise backgroundsI believe that friends who have used JavaScript before have encountered asynchronous callback Hell (callback Hell), n multiple callback nesting not only makes the code read very difficult, maintenance is also very inconvenient.In fact, C # Task before the advent of a similar scenario, the Async Programming mode era, with Action and Func do callbacks are also very popular, but also aware that too many callback
Asynchronous loading has always been a headache for me, the undergraduate phase of the asynchronous synchronous communication has made me very confused. But after contacting the asynchronous load in JS I really realized that the so-called asynchronous loading is like a customer service center, and each worker has a workflow line. Below I will detail the implementation method of Pronise.Promise is an object that is used to pass an asynchronous operatio
, success: function (data) { $.ajax ({ //...});});} );3. Consider the scenario where if we send two AJAX requests at the same time and then do one of the next things after the two requests are successfully returned, think of the assumption that the callback will be appended to the respective invocation location just in the previous way. Isn't it very difficult? The ability to see that asynchronous operations like Ajax in JavaScript can lead to comp
Promises is an abstraction that makes code asynchronous behavior more elegant, and it is likely to be the next programming paradigm for JavaScript, a promise that represents the outcome of a task, regardless of whether the task is completed or not.
Native promise objects have been provided in some modern browsers, and they follow the promise/a+ standard. In jque
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.