123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
-
- </body>
- <script>
- let orderTagList = [1,2]
- let abb = {a:1}
- let acc = {b:2}
- Promise.prototype._all = function(promises) {
- let results = [];
- let promiseCount = 0;
- let promisesLength = promises.length;
- return new Promise(function(resolve, reject) {
- for (let val of promises) {
- Promise.resolve(val).then(function(res) {
- console.log(res)
- promiseCount++;
- results.push({a:res});
- // results[i] = res;
- // 当所有函数都正确执行了,resolve输出所有返回结果。
- if (promiseCount === promisesLength) {
- return resolve(results);
- }
- }, function(err) {
- return reject(err);
- });
- }
- });
- };
- Promise.prototype._all([orderTagList,abb,acc]).then((e)=>{
- console.log(e,'2');
- })
- </script>
- </html>
|