topic description
let _resolve;
let promise2 = new Promise((resolve, reject) => _resolve = resolve);
promise2.then((data)=>{
console.log(data);
})
setTimeout(()=>{
_resolve(2000000000);
},7000)
The execution result of code?
Why is this?
let _resolve;
let promise2 = new Promise((resolve, reject) => _resolve = resolve);
promise2.then((data)=>{
console.log(data);
})
setTimeout(()=>{
_resolve(2000000000);
},7000)
The execution result of code?
Why is this?
wait 7 seconds to print 2000000000, because it takes 7 seconds for you to let it complete
Brother you mean that the assignment has no parentheses, that is, it is not executed. The real execution is in the timeout call. All successful callbacks are that the data will receive this data, and the hope from the timeout call will help you
.Previous: Wechat embedded H5 page, localstorage will be cleared after exit, there is no permanent cache method
Next: Knowing the coordinates of sliding verification, what algorithm is used to calculate the path?
How does the code return only the result after the last asynchronous operation in the for loop is completed as shown in the figure? Please stop by and give me a hand. ...
this is encapsulated function request(url, params) { let promise = new Promise(function (resolve, reject) { wx.request({ url: url, data: params, header: { X-Token-With : token ...
for example Promis.all([p1,p2]).then((p1result,p2result)=>{}); if p1 returns [1mem2p3] p2 returns [4mage5magin6] the final result is a parameter [1mem2magin3], what should I do if I want to use the results of two p objects respectively? ...
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 ,()=...
recently in learning the koa framework to build a node environment, writing a small case requires the following: the node program reads a path, and if it is a folder, put the folder name into the list collection. Promise is used in the program to do asy...
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...
when reading Promise : var promise1 = new Promise(function(resolve, reject) { setTimeout(resolve, 100, foo ); }); if an error is thrown in the executor function, the promise state is rejected. The return value of the executor function is ignored...
doctorComments(this.$route.params.hid, this.$route.params.fid, this.doctorHisId, this.createdon, this.pageno, 5) 1.axios .then(d => { 2. let dc = new Array() for(let i=0;i<d.list.length;iPP){ dc[i] = {doctorComments:d.list[i],isZhanshiC...
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...
let p1 = ()=>{ data = xxxx xxx true false return new Promise((res,rej)=>{ res(data) }) } p2 p3 promise let p2 = .... let p3 = .... p1() .then( (data)=>{ if (data) { return p2 } ...
a.js a.js module.exports = { list: async () => { return await axios.get(getIntelligentPlatform) }, } b.js b.js const { list } = require( .. models meibrain ) list().then(res => { console.log(res.data.obj) }) ...
util.getToken (). Then (token = > { return util.wxRequest({ url: ports.orderList, method: POST , data: { user_id: 32793, ofstatus:10}, header: { X-Auth-Token : token, content-type ...
Source code see here Promise.prototype.then = function(onFulfilled, onRejected) { if (this.constructor !== Promise) { return safeThen(this, onFulfilled, onRejected); } var res = new Promise(noop); handle(this, new Handler(onFulfilled, onR...
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...
vue.js environment, you need to fill in multiple objects on the page and add them to the backend in batches. Currently, there are two APIs in api.js: apiCheckDuplicated (name) apiCreateNew (name) ajax calls implemented by axios. now the page has en...
recently, I am doing a web crawler, first grab the list page, then get the url, of all the content pages of the list page, and then call the url loop of all the list pages to the crawling method, which leads to the uncontrollable crawling order. I want ...
The project uses axios, packaging to open Index.html as a local file and does not report errors in a lower version browser, but once deployed to the server, it will report errors that are not defined by promise. tried to introduce the babel-polyfill ...
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...
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,? ...