javascript - Why new Promise.all().then() worked? -
let iconsloaded = new promise((resolve, reject) => { new promise.all( object.keys(icons).map(iconname => { const provider = icons[iconname][2] || defaulticonprovider; // ionicons return provider.getimagesource( iconname.replace(replacesuffixpattern, ''), icons[iconname][0], icons[iconname][1] ) }) ).then(sources => { object.keys(icons) .foreach((iconname, idx) => iconsmap[iconname] = sources[idx]) // call resolve (and done) resolve(true); }) });
please me understand above code promise.all()
i know promise object has call() method,but know it's static method, should not used above,eg: new promise.all(),but give me no error. why-why-why...
the code above has no error
but, code following wrong..give me error ðŸ˜
let p2 = new promise(function(resolve, reject){ console.log('p2 body') resolve('p2 resolve') }) let p1 = new promise(function(resolve, reject){ console.log('p1 body') resolve('p1 resolve') }) var p = new promise(function(resolve, reject){ new promise.all([p2,p1]) .then(function(){ console.log('all(p2, p1) then') }) console.log('p body') })
Comments
Post a Comment