{"id":191304,"date":"2020-05-28T08:11:28","date_gmt":"2020-05-28T00:11:28","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=191304"},"modified":"2020-05-17T16:12:35","modified_gmt":"2020-05-17T08:12:35","slug":"introduction-to-es6-2","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/introduction-to-es6-2.html","title":{"rendered":"ES6 Promise \u5bf9\u8c61\u4ecb\u7ecd"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | ES6\uff0c \u5168\u79f0 ECMAScript 6.0 \uff0c\u662f JavaScript \u7684\u4e0b\u4e00\u4e2a\u7248\u672c\u6807\u51c6\uff0c2015.06 \u53d1\u7248\u3002ES6 \u4e3b\u8981\u662f\u4e3a\u4e86\u89e3\u51b3 ES5 \u7684\u5148\u5929\u4e0d\u8db3\uff0c\u6bd4\u5982 JavaScript \u91cc\u5e76\u6ca1\u6709\u7c7b\u7684\u6982\u5ff5\uff0c\u4f46\u662f\u76ee\u524d\u6d4f\u89c8\u5668\u7684 JavaScript \u662f ES5 \u7248\u672c\uff0c\u5927\u591a\u6570\u9ad8\u7248\u672c\u7684\u6d4f\u89c8\u5668\u4e5f\u652f\u6301 ES6\uff0c\u4e0d\u8fc7\u53ea\u5b9e\u73b0\u4e86 ES6 \u7684\u90e8\u5206\u7279\u6027\u548c\u529f\u80fd\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n \u6982\u8ff0<\/strong><\/div>\n \u662f\u5f02\u6b65\u7f16\u7a0b\u7684\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n \u4ece\u8bed\u6cd5\u4e0a\u8bf4\uff0cPromise \u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u4ece\u5b83\u53ef\u4ee5\u83b7\u53d6\u5f02\u6b65\u64cd\u4f5c\u7684\u6d88\u606f\u3002<\/p>\n Promise \u72b6\u6001<\/strong><\/div>\n \u72b6\u6001\u7684\u7279\u70b9<\/strong><\/span><\/div>\n Promise \u5f02\u6b65\u64cd\u4f5c\u6709\u4e09\u79cd\u72b6\u6001\uff1apending\uff08\u8fdb\u884c\u4e2d\uff09\u3001fulfilled\uff08\u5df2\u6210\u529f\uff09\u548c rejected\uff08\u5df2\u5931\u8d25\uff09\u3002\u9664\u4e86\u5f02\u6b65\u64cd\u4f5c\u7684\u7ed3\u679c\uff0c\u4efb\u4f55\u5176\u4ed6\u64cd\u4f5c\u90fd\u65e0\u6cd5\u6539\u53d8\u8fd9\u4e2a\u72b6\u6001\u3002<\/p>\n Promise \u5bf9\u8c61\u53ea\u6709\uff1a\u4ece pending \u53d8\u4e3a fulfilled \u548c\u4ece pending \u53d8\u4e3a rejected \u7684\u72b6\u6001\u6539\u53d8\u3002\u53ea\u8981\u5904\u4e8e fulfilled \u548c rejected \uff0c\u72b6\u6001\u5c31\u4e0d\u4f1a\u518d\u53d8\u4e86\u5373 resolved\uff08\u5df2\u5b9a\u578b\uff09\u3002<\/p>\n const p1 = new Promise(function(resolve,reject){\r\n resolve('success1');\r\n resolve('success2');\r\n}); \r\nconst p2 = new Promise(function(resolve,reject){ \r\n resolve('success3'); \r\n reject('reject');\r\n});\r\np1.then(function(value){ \r\n console.log(value); \/\/ success1\r\n});\r\np2.then(function(value){ \r\n console.log(value); \/\/ success3\r\n});<\/pre>\n |