the meaning of 1.Promise
Promise is a solution to asynchronous programming that is more logical and powerful than traditional solutions (callback functions and events).
The so-called promise is simply a container that holds the result of an event (usually an asynchronous operation) that will end in a future. Syntactically, p
, the code is less, solve the callback Hell pyramid defect
2, async in the second parameter callback function, you can handle the error uniformly (it is recommended to use different error classes to distinguish)
3, the result of successful return datas can be summarized into an array for easy processingThird, Promise
Expand
Promise Knowledge
new Promise()
//
First, the preface
In order to get the front end back to heaven from the hell of the callback, JQuery also introduced the concept of Promise. Promise is an abstraction that makes code asynchronous behavior more elegant, and with it we can write asynchronous code like write synchronization code. JQuery began with the 1.5 version of the COMMONJS promise/a specific
can obtain messages for asynchronous operations, characterized by:
1 The state of the object is unaffected by the outside world. The Promise object represents an asynchronous operation with three states: pending (in progress), fulfilled (succeeded), and rejected (failed).
2 Once the state has changed, it will not change, and can get the result at any time. There are only two possible changes in the state of the P
In this article, we will explore the concepts of Deferred and Promise in JavaScript. They are a very important feature in the JavaScript Toolkit (such as Dojo and MochiKit, it has also made its debut in the popular JavaScript library jQuery (which is already in version 1.5 ). Deferred provides an abstract non-blocking solution (such as Ajax Request Response). It creates a "promise" object to return a respon
A few days ago in the interview, encountered such a question:
Name the execution result of the following code:
settimeout (function () {
console.log (1)
}, 0);
New Promise (function executor (resolve) {
resolve ();
}). Then (function () {
console.log (2);
}); 2,1
(function test () {
settimeout (function () {Console.log (4)}, 0);
New Promise (function executor (resolve) {
console.log (
implementing the next operation.
Starting with ES6, promise objects can solve the above problems. What is a Promise object
A Promise object can be understood as an action to be performed once, and a promise object can be used after a chain call
To organize your code to make it more intuitive. Resolve and Reject
First
In this article, we explore the concepts of Deferred and Promise in JavaScript, a very important feature of JavaScript toolkits (such as Dojo and MochiKit), and have recently been unveiled in the popular JavaScript library for the first time. JQuery (already a version of the 1.5 thing). Deferred provides an abstract non-blocking solution, such as a response to an AJAX request, that creates a "promise" objec
In this article, we will explore the concepts of Deferred and Promise in JavaScript. They are a very important feature in the JavaScript Toolkit (such as Dojo and MochiKit, it has also made its debut in the popular JavaScript library jQuery (which is already in version 1.5 ). Deferred provides an abstract non-blocking solution (such as Ajax Request Response). It creates a "promise" object to return a respon
Basic knowledge: Promise (finishing)(from the Cattle network) The following statement about promise, the wrong is (D)A. Both resolve and reject directly generate a promise object that enters the corresponding state, and its parameters are passed in the corresponding state when passing parameters, which can be obtained in the parameters of the completion callbackB
Many languages, in order to process asynchronous patterns more in the usual order, contain an interesting scenario library, which is called promises,deferreds, or futures. The promises of JavaScript can facilitate separation of concerns to replace tightly coupled interfaces. This article is about the JavaScript promises based on the PROMISES/A standard. [Http://wiki.commonjs.org/wiki/Promises/A]
Use cases for promise:
Executing rules
Multip
What is promise? Is it an object? Array? Function? We can print it out directly, console. dir (promise)
It can be seen that promise is a constructor, which has the "all", "reject", and "resolve" methods on its own, and the then and catch methods on its prototype. In this case, the then and catch methods must be applied to the objects created by using
The deferred object of the Promise objectPortal Instance Environment setup----------------------------------------------1. What is scaffolding: Others set up a good environment to download and useAjaxParallel/serialPromise.all-----------------------------------------------Promise.allRequest two at the same time and then return as if there is one error the other one also goes wrong-----------------------------------------------Const Getjson = function
Javascript Promise learning notes, javascriptpromise
1. Definition: Promise is a component that abstracts asynchronous processing objects and performs various operations on them. It uses asynchronous processing objects and asynchronous processing rulesUnified Interface.
2. API defined in ES6 Promises standard:
A)Constructor: new is used for instantiation,Var promise
What is promise?In fact, promise is a class, and this class has become the ES6 standard, is one of the important characteristics of ECMAScript 6 specification. This class is now supported in Chrome32, OPERA19, and Firefox29 versions, so look at es6-promise if you want to use them on all browsers.ES6 's Promises is an implementation of the promises/a+ proposal. Th
, solve the callback Hell pyramid defect2, async in the second parameter callback function, you can handle the error uniformly (it is recommended to use different error classes to distinguish)3, the result of successful return datas can be summarized into an array for easy processingThird, PromiseExpandPromise Knowledgenew Promise()// promise在new的时候已经开始运行 new Promise
promise is a very simple concept, and even if you don't have a chance to use it, chances are that you've learned about it. Promise is a valuable constructor that can help you avoid using nested anonymous methods and assemble asynchronous code in a more readable way. Here we will introduce the 6 simplest features that we would like to help you with. Before we begin our formal presentation, we'd like to look
The previous chapter describes the Future type and how to use it to write high readability, high combination asynchronous execution code.
Future is just one part of the whole puzzle: it is a read-only type that allows you to use it to compute the value, or to handle errors that occur in calculations. But before that, there has to be a way to put that value in. In this chapter, you will see how to achieve this by Promise type. type
This article mainly introduces the simple implementation of asynchronous programming promise mode, and analyzes each step. If you need it, refer
Asynchronous programmingJavascript asynchronous programming: popular programming methods in the web2.0 era. We usually use code more or less. The most typical is asynchronous ajax, which sends asynchronous requests and binds callback functions, after the request is responded, the specified callback function i
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
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.