can be run in Chrome. The program details are shown below:
will the current task queue be rolled back to the status of the Project sibling as soon as you execute reject,?
will the current task queue be rolled back to the status of the Project sibling as soon as you execute reject,?
return reject
has no special meaning. Promise makes Promise complete or failed through resolve
and reject
. Your return reject ('2')
is executed reject ('2')
and pops out.
if you return in advance, it will cause the Promise to be pending
state.
return will jump out of the function, not return. If you have code after reject, it will be executed
here reject
is a function. What is your function definition?
there is no difference, the same as the answer of the previous two bigwigs. Is to interrupt the execution of the current function. If there is no return, it will continue later, if there is no effect when rej/res is executed.
new Promise((res,rej)=>{
res();
console.log(1);
rej();
console.log(2)
})
Direct output: 1. And this is the resolve state.
Promise{<resolved>: undefined}
Previous: How does hexo add columns to list pages?
Next: Can java @ Vaild be used for annotation verification on objects?
as soon as I came into contact with promise, I wrote a demo by myself. Ask . Why my then only executes once, and how to make it execute multiple times var test = 0; var promise = new Promise(resolve => { $( .btn ).on( click ,()=...
a () { return new Promise((res, rej) => { : getData().then(res => { this.data = res.data.reslut console.log(this.data) }) }); } the a method is defined in vue , and the a method is ca...
write a chained call as follows: new Man( lan ).sleep(3).eat( apple ).sleep(3).eat( banana ); output: hello, lan--> (pause 3s)-> lan eat apple-> (pause 3s)-> lan eat banana my code is as follows: class Man { constructor(name) { th...
I have reviewed articles of various promise implementations, all of which indicate that it is necessary to maintain a _ deferreds to save the callback function set information registered by the then method, and some implementations maintain onResolve...
at present, I have written the login operation in app.js. After obtaining Wechat s code, I obtain the authentication access-token from my own server. the code is as follows app.js onLaunch: function () { wx.login({ success: ...
functiong getPromise(){ return Promise.resolve( something ); } let getSomething = async function(){ let a = await getPromise(); return a; } The async function returns a promise object, so there is no way to return a non-promise ob...
perPageFiles = filenames.slice(articleIndex, articleIndex + perPage); perPageFiles.forEach(function(filename, index) { fs.readFile(fileDirectory + filename + .md , utf-8 , function(err, data) { if (err) throw err; perPageDatas[index].arti...
Database query function query(sql) { return new promise((resolve, reject) => { pool.getConnection(function (err, conn) { if (err) { reject(err); } else { conn.query(sql, function (e...
as shown in the figure above, what is not clear is: why then uses dot syntax, while catch and finally use [] syntax because catch and finally are keywords in js? I don t know what I don t know about this. this is the github address of this polyfi...
Both then and catch in promise can handle exceptions, so what s the difference between them in handling exceptions? Promise.reject( error ).then(()=> {}, val=> { console.log(val); }); Promise.reject( error ).catch(val=> { console...
fetch( http: 10.3.134.173 jsonp-test data dish_getbypage.php?start=1 , ).then((response)=> response.json() ).then((res)=>{ console.log(res[0].name); }); fetch( http: 10.3.134.173 jsonp-test data dish_getbypage.php?s...
function loadUploadFn() { return new Promise(function(resolve, reject) { var len = 0; ** * var uploadListIns = $upload.render({ elem: -sharpuploadBtn , url: .. accountManager uploadWechatCod...
the return of err and catch does not default to reject. new Promise((resolve, reject) => { setTimeout(() => { if (0) { resolve(10) } else { reject(11) } }, 0) ...
how to reset resolve or Promise after the first resolve so that the next resolve has output I am writing login operations, and sometimes I encounter login failures. You need to reset resolve or Promise, so that you can have resolve when you initiate a...
when using bluebird and nodejs native Promise to execute the following code, the order of execution is somewhat different. What is the reason for this? ** * bluebird, 2 3 5 6 1 4 * Promise 2 3 5 6 4 1 * var Promise = require("bluebird"...
function loadImageAsync(url) { return new Promise(function(resolve, reject) { throw new Error( BUG FOREVER ) const image = new Image(); image.onload = function() { resolve(image); }; image.o...
encountered an interview question, usually after an asynchronous operation error will enter. Catch (), now has to enter after three errors, how to achieve this. ...
the second interface uses the data returned by the first interface name , and then splices it without promise.all or global variables. Solve? function ajax(url,datas){ return new Promise((resolve,reject) => { $.ajax({...
The code is as follows: how can I capture the reject? of any previous task in the tail catch var task1 = new Promise(function(resolve, reject){ resolve( success ); }); var task2 = new Promise(function(resolve, reject){ reject( error ); }); t...
< H1 > Code < H1 > undefined (node:5784) UnhandledPromiseRejectionWarning: TypeError: Cannot read property name of undefined at say (D: NodeJS Test test2.js:18:22) ...