This article mainly introduces Deferred of deferred in jQuery. the promise () method reminds you to pay attention to deferred. promise () and jQuery's. the difference between promise () instance methods. For more information, see
Deferred. promise () and. promise ()
These t
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
Data Link: http://liubin.org/promises-book/#what-is-promise1. What is PromisePromise is a component that abstracts objects asynchronously and handles various operations on them.2. What is the form of expression? callback function: Getasync ("FileA.txt", function (error, result) {if (error) {////failed to handle throw error;}//successful processing}); Asynchronous processing using promise: var promise = Geta
[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
Reprinted from: http://segmentfault.com/a/1190000002591145Promise Core NotesPromise specifications, please Baidu Search prommise/a+ specifications, promise Core is there is a then method. In related terms, promise refers to having a thenmethod, and the method can trigger the object or function of a particular behavior.Start: Understand promise in this wayRecall w
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
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
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
, 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
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
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
, 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
Issues caused by low-version browsersRecently developed a project based on webpack+babel+react , generally local is in chrome browsing above development, Chrome browser development because support most of the new JS features, so generally do not need polyfill, such as Promise,string instance includes method. Even in the low version of the browser, through babel-runtime the Polyfill can also be converted, but things do not unexpectedly, the project in
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
What is promise
Promise is a more elegant pattern of writing asynchronous code, allowing asynchronous operation code to be written and read like synchronous code, such as the following example of an asynchronous request:
$.get ("/js/script,js", function () {
//callback to do
})
Can be rewritten as promise mode:
var
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
Detail Api:https://github.com/kriskowal/q/wiki/api-referenceQ provides a way to implement promise, which is now much more in node. Because there is no Chinese API, I will simply translate it. Welcome to shoot Bricks ...First, Core Promise Methods1, Promise.then (onfulfilled, onrejected, OnProgress)Let's not talk about this.2, Promise.catch (onrejected)It is equivalent to: promise.then (undefined, onrejected
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.