{"id":229430,"date":"2020-12-12T06:09:26","date_gmt":"2020-12-11T22:09:26","guid":{"rendered":"http:\/\/4563.org\/?p=229430"},"modified":"2020-12-12T06:09:26","modified_gmt":"2020-12-11T22:09:26","slug":"%e7%8e%b0%e4%bb%a3-javascript%ef%bc%9a-es6-%e4%b8%ad%e7%9a%84-imports%ef%bc%8c-exports%ef%bc%8c-let%ef%bc%8c-const-%e5%92%8c-promise","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=229430","title":{"rendered":"\u73b0\u4ee3 JavaScript\uff1a ES6+ \u4e2d\u7684 Imports\uff0c Exports\uff0c Let\uff0c Const \u548c Promise"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u73b0\u4ee3 JavaScript\uff1a ES6+ \u4e2d\u7684 Imports\uff0c Exports\uff0c Let\uff0c Const \u548c Promise               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : GrapeCityChina <\/span>  <span><i><\/i> 6<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5728\u8fc7\u53bb\u51e0\u5e74\u91cc\uff0cJavaScript \u6709\u5f88\u591a\u7684\u66f4\u65b0\u3002\u5982\u679c\u4f60\u60f3\u63d0\u5347\u5199\u4ee3\u7801\u7684\u80fd\u529b\uff0c\u8fd9\u4e9b\u66f4\u65b0\u5c06\u4f1a\u5bf9\u4f60\u6709\u975e\u5e38\u5927\u7684\u5e2e\u52a9\u3002<\/p>\n<p>\u5bf9\u4e8e\u7a0b\u5e8f\u5458\u6765\u8bf4\uff0c\u4e86\u89e3\u8fd9\u95e8\u8bed\u8a00\u7684\u6700\u65b0\u53d1\u5c55\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u5b83\u80fd\u4f7f\u4f60\u8ddf\u4e0a\u6700\u65b0\u8d8b\u52bf\uff0c\u63d0\u9ad8\u4ee3\u7801\u8d28\u91cf\uff0c\u5728\u5de5\u4f5c\u4e2d\u51fa\u7c7b\u62d4\u8403\uff0c\u4ece\u800c\u8fdb\u4e00\u6b65\u63d0\u5347\u4f60\u7684\u85aa\u8d44\u5f85\u9047\u3002<\/p>\n<p>\u7279\u522b\u5730\uff0c\u5982\u679c\u4f60\u60f3\u5b66\u4e60\u50cf React \u3001Angular \u6216 Vue \u8fd9\u6837\u7684\u6846\u67b6\uff0c\u4f60\u5fc5\u987b\u638c\u63e1\u8fd9\u4e9b\u6700\u65b0\u7684\u7279\u6027\u3002<\/p>\n<p>\u6700\u8fd1\uff0cJavaScript \u589e\u52a0\u4e86\u8bb8\u591a\u6709\u7528\u7684\u529f\u80fd\uff0c\u6bd4\u5982<strong>Nullish coalescing operator, optional chaining, Promises, async\/await, ES6 destructuring<\/strong>,\u7b49\u7b49\u3002<\/p>\n<p>\u90a3\u4e48\u73b0\u5728\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u6bcf\u4e2a JavaScript \u5f00\u53d1\u8005\u90fd\u5e94\u8be5\u77e5\u9053\u7684\u6982\u5ff5\u3002<\/p>\n<h2><strong>JavaScript \u4e2d\u7684 Let \u548c const<\/strong><\/h2>\n<p>\u5728 ES6 \u4e4b\u524d\uff0cJavaScript \u4f7f\u7528 var \u5173\u952e\u5b57\u6765\u58f0\u660e\u53d8\u91cf\uff0cvar \u53ea\u6709\u5168\u5c40\u4f5c\u7528\u57df\u548c\u51fd\u6570\u4f5c\u7528\u57df\uff0c\u6240\u8c13\u5168\u5c40\u4f5c\u7528\u57df\u5c31\u662f\u5728\u4ee3\u7801\u7684\u4efb\u4f55\u4f4d\u7f6e\u90fd\u80fd\u8bbf\u95ee var \u58f0\u660e\u7684\u53d8\u91cf\uff0c\u800c\u51fd\u6570\u4f5c\u7528\u57df\u5728\u53d8\u91cf\u58f0\u660e\u7684\u5f53\u524d\u51fd\u6570\u5185\u90e8\u8bbf\u95ee\u53d8\u91cf\u3002\u6b64\u65f6\u662f\u6ca1\u6709\u5757\u7ea7\u4f5c\u7528\u57df\u7684\u3002<\/p>\n<p>\u968f\u7740 let \u548c const \u8fd9\u4e24\u4e2a\u5173\u952e\u5b57\u7684\u6dfb\u52a0\uff0cJS \u589e\u52a0\u4e86\u5757\u7ea7\u4f5c\u7528\u57df\u7684\u6982\u5ff5\u3002<\/p>\n<h4><strong>\u5982\u4f55\u5728 JavaScript \u4e2d\u4f7f\u7528 let<\/strong><\/h4>\n<p>\u5f53\u6211\u4eec\u5728\u7528 let \u58f0\u660e\u53d8\u91cf\u65f6\uff0c\u7528\u4e8e\u58f0\u660e\u4e00\u6b21\u4e4b\u540e\u5c31\u4e0d\u80fd\u518d\u4ee5\u76f8\u540c\u7684\u540d\u79f0\u91cd\u65b0\u58f0\u660e\u5b83\u3002<\/p>\n<pre><code>\/\/ ES5 Code  var value =  10;  console.log(value);  \/\/ 10  var value =  \"hello\";  console.log(value);  \/\/ hello  var value =  30;  console.log(value);  \/\/ 30 <\/code><\/pre>\n<p>\u5982\u4e0a\u6240\u793a\uff0c\u6211\u4eec\u591a\u6b21\u4f7f\u7528 var \u5173\u952e\u5b57\u91cd\u65b0\u58f0\u660e\u4e86\u53d8\u91cf\u503c\u3002<\/p>\n<p>\u5728 ES6 \u4e4b\u524d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 var \u91cd\u65b0\u58f0\u660e\u4e4b\u524d\u5df2\u7ecf\u58f0\u660e\u8fc7\u7684\u53d8\u91cf\uff0c\u8fd9\u5c31\u4f1a\u5bfc\u81f4\u4e86\u4e00\u4e2a\u95ee\u9898\uff1a\u5982\u679c\u6211\u4eec\u5728\u4e0d\u77e5\u60c5\u7684\u60c5\u51b5\u4e0b\uff0c\u5728\u5176\u4ed6\u5730\u65b9\u91cd\u65b0\u58f0\u660e\u4e86\u8be5\u53d8\u91cf\uff0c\u5f88\u6709\u53ef\u80fd\u4f1a\u8986\u76d6\u539f\u5148\u53d8\u91cf\u7684\u503c\uff0c\u9020\u6210\u4e00\u4e9b\u96be\u4ee5\u8c03\u8bd5\u7684\u95ee\u9898\u3002<\/p>\n<p>\u6240\u4ee5\uff0cLet \u89e3\u51b3\u5f88\u597d\u5730\u89e3\u51b3\u6b64\u95ee\u9898\u3002\u5f53\u4f60\u4f7f\u7528 let \u91cd\u65b0\u58f0\u660e\u53d8\u91cf\u503c\u65f6\uff0c\u5c06\u4f1a\u62a5\u9519\u3002<\/p>\n<pre><code>\/\/ ES6 Code let value = 10; console.log(value); \/\/ 10  let value = \"hello\"; \/\/ Uncaught SyntaxError: Identifier 'value' has already been declared  <\/code><\/pre>\n<p>\u4f46\u662f\uff0c\u4ee5\u4e0b\u4ee3\u7801\u662f\u5408\u6cd5\u7684:<\/p>\n<pre><code>\/\/ ES6 Code let value = 10; console.log(value); \/\/ 10  value = \"hello\"; console.log(value); \/\/ hello  <\/code><\/pre>\n<p>\u6211\u4eec\u53d1\u73b0\u4e0a\u9762\u7684\u4ee3\u7801\u770b\u8d77\u6765\u6ca1\u4ec0\u4e48\u95ee\u9898\uff0c\u662f\u56e0\u4e3a\u6211\u4eec\u91cd\u65b0\u7ed9 value \u53d8\u91cf\u8d4b\u4e86\u4e00\u4e2a\u65b0\u503c\uff0c\u4f46\u662f\u5e76\u6ca1\u6709\u91cd\u65b0\u58f0\u660e\u3002<\/p>\n<p>\u6211\u4eec\u6765\u770b\u4e0b\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n<pre><code>\/\/ ES5 Code var isValid = true; if(isValid) {   var number = 10;   console.log('inside:', number); \/\/ inside: 10 } console.log('outside:', number); \/\/ outside: 10  <\/code><\/pre>\n<p>\u5982\u4e0a\u6240\u793a\uff0c\u5728\u4f7f\u7528 var \u58f0\u660e\u53d8\u91cf\u65f6\uff0c\u53ef\u4ee5\u5728 if \u5757\u4e4b\u5916\u8bbf\u95ee\u8be5\u53d8\u91cf\u3002<\/p>\n<p>\u800c\u4f7f\u7528 let \u58f0\u660e\u7684 number \u53d8\u91cf\u53ea\u80fd\u5728 if \u5757\u5185\u8bbf\u95ee\uff0c\u5982\u679c\u5728 if \u5757\u5916\u8bbf\u95ee\u5c06\u4f1a\u62a5\u9519\u3002<\/p>\n<p>\u6211\u4eec\u6765\u770b\u4e0b\u63a5\u4e0b\u6765\u7684\u4ee3\u7801<\/p>\n<pre><code> \/\/ ES6 Code let isValid = true; if(isValid) {   let number = 10;   console.log('inside:', number); \/\/ inside: 10 } console.log('outside:', number); \/\/ Uncaught ReferenceError: number is not defined  <\/code><\/pre>\n<p>\u5982\u4e0a\u8ff0\u4ee3\u7801\u6240\u793a\uff0c\u4f7f\u7528 let \u5206\u522b\u5728 if \u5757\u5185\u3001if \u5757\u5916\u58f0\u660e\u4e86 number \u53d8\u91cf\u3002\u5728 if \u5757\u5916\uff0cnumber \u65e0\u6cd5\u88ab\u8bbf\u95ee\uff0c\u56e0\u6b64\u4f1a\u51fa\u73b0\u5f15\u7528\u9519\u8bef\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u5982\u679c\u53d8\u91cf number \u5728 if \u5757\u5916\u5df2\u7ecf\u58f0\u660e\uff0c\u5c06\u4f1a\u51fa\u73b0\u4e0b\u9762\u7684\u7ed3\u679c\u3002<\/p>\n<pre><code> \/\/ ES6 Code let isValid = true; let number = 20;  if(isValid) {   let number = 10;   console.log('inside:', number); \/\/ inside: 10 }  console.log('outside:', number); \/\/ outside: 20  <\/code><\/pre>\n<p>\u73b0\u5728\u5728\u5355\u72ec\u7684\u8303\u56f4\u5185\u6709\u4e24\u4e2a number \u53d8\u91cf\u3002\u5728 if \u5757\u5916\uff0cnumber \u7684\u503c\u4e3a 20 \u3002<\/p>\n<pre><code> \/\/ ES5 Code for(var i = 0; i &lt; 10; i++){  console.log(i); } console.log('outside:', i); \/\/ 10    <\/code><\/pre>\n<p>\u5f53\u4f7f\u7528 var \u5173\u952e\u5b57\u65f6\uff0ci \u5728 for \u5faa\u73af\u4e4b\u5916\u4e5f\u53ef\u4ee5\u8bbf\u95ee\u5230\u3002<\/p>\n<pre><code> \/\/ ES6 Code for(let i = 0; i &lt; 10; i++){  console.log(i); }  console.log('outside:', i); \/\/ Uncaught ReferenceError: i is not defined  <\/code><\/pre>\n<p>\u800c\u4f7f\u7528 let \u5173\u952e\u5b57\u65f6\uff0c\u5728 for \u5faa\u73af\u5916\u90e8\u662f\u4e0d\u53ef\u8bbf\u95ee\u7684\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u6b63\u5982\u4e0a\u8ff0\u793a\u4f8b\u4ee3\u7801\u6240\u793a\uff0clet \u58f0\u660e\u7684\u53d8\u91cf\u53ea\u80fd\u5728\u5757\u5185\u90e8\u53ef\u7528\uff0c\u800c\u5728\u5757\u5916\u90e8\u4e0d\u53ef\u8bbf\u95ee\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u5bf9\u5927\u62ec\u53f7\u521b\u5efa\u4e00\u4e2a\u5757\uff0c\u5982\u4e0b:<\/p>\n<pre><code>let i = 10; {  let i = 20;  console.log('inside:', i); \/\/ inside: 20  i = 30;  console.log('i again:', i); \/\/ i again: 30 }  console.log('outside:', i); \/\/ outside: 10   <\/code><\/pre>\n<p>\u524d\u9762\u6709\u63d0\u5230\uff0clet \u5728\u540c\u4e00\u4e2a\u5757\u4e2d\u4e0d\u80fd\u91cd\u65b0\u58f0\u660e\u53d8\u91cf\uff0c\u4e0d\u8fc7\u53ef\u4ee5\u5728\u53e6\u4e00\u4e2a\u5757\u4e2d\u91cd\u65b0\u58f0\u660e\u3002\u5982\u4e0a\u4ee3\u7801\u6240\u793a\uff0c\u6211\u4eec\u5728\u5757\u5185\u91cd\u65b0\u58f0\u660e\u4e86 i\uff0c\u5e76\u8d4b\u503c 20\uff0c\u8be5\u53d8\u91cf\u4ec5\u53ef\u5728\u8be5\u5757\u4e2d\u4f7f\u7528\u3002<\/p>\n<p>\u5728\u5757\u5916\uff0c\u5f53\u6211\u4eec\u6253\u5370\u53d8\u91cf\u65f6\uff0c\u6211\u4eec\u5f97\u5230\u7684\u662f 10 \u800c\u4e0d\u662f\u4e4b\u524d\u5206\u914d\u7684\u503c\uff0c\u8fd9\u662f\u56e0\u4e3a\u5757\u5916\uff0c\u5185\u90e8\u53d8\u53d8\u91cf i \u662f\u4e0d\u5b58\u5728\u7684\u3002<\/p>\n<p>\u5982\u679c\u5728\u5757\u5916\u672a\u58f0\u660e\u53d8\u91cf\uff0c\u90a3\u4e48\u5c06\u4f1a\u62a5\u9519:<\/p>\n<pre><code> {  let i = 20;  console.log('inside:', i); \/\/ inside: 20  i = 30;  console.log('i again:', i); \/\/ i again: 30 }  console.log('outside:', i); \/\/ Uncaught ReferenceError: i is not defined <\/code><\/pre>\n<h4><strong>\u5982\u4f55\u5728 JavaScript \u4f7f\u7528 const<\/strong><\/h4>\n<p>const \u5173\u952e\u5b57\u5728\u5757\u7ea7\u4f5c\u7528\u57df\u4e2d\u7684\u5de5\u4f5c\u65b9\u5f0f\u4e0e let \u5173\u952e\u5b57\u5b8c\u5168\u76f8\u540c\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u6765\u770b\u4e0b\u4ed6\u4eec\u7684\u533a\u522b\u3002<\/p>\n<p>const \u58f0\u660e\u7684\u53d8\u91cf\u4e3a\u5e38\u91cf\uff0c\u5176\u503c\u662f\u4e0d\u80fd\u6539\u53d8\u7684\u3002\u800c let \u58f0\u660e\u7684\u53d8\u91cf\uff0c\u53ef\u4ee5\u4e3a\u5176\u8d4b\u4e00\u4e2a\u65b0\u503c\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n<pre><code>let number = 10; number = 20; console.log(number); \/\/ 20 <\/code><\/pre>\n<p>\u4f46\u662f\u4ee5\u4e0b\u60c5\u51b5\uff0c\u6211\u4eec\u4e0d\u80fd\u8fd9\u6837\u4f7f\u7528 const \u3002<\/p>\n<pre><code> const number = 10; number = 20; \/\/ Uncaught TypeError: Assignment to constant variable.   <\/code><\/pre>\n<p>\u6211\u4eec\u751a\u81f3\u4e0d\u80fd\u4f7f\u7528 const \u50cf\u4e0b\u9762\u4e00\u6837\u91cd\u65b0\u58f0\u660e\u3002<\/p>\n<pre><code>const number = 20; console.log(number); \/\/ 20  const number = 10; \/\/ Uncaught SyntaxError: Identifier 'number' has already been declared  <\/code><\/pre>\n<p>\u73b0\u5728\uff0c\u770b\u4e0b\u9762\u7684\u4ee3\u7801:<\/p>\n<pre><code>const arr = [1, 2, 3, 4]; arr.push(5); console.log(arr); \/\/ [1, 2, 3, 4, 5]  <\/code><\/pre>\n<p>\u6211\u4eec\u8bf4\u8fc7 const \u58f0\u660e\u7684\u5e38\u91cf\uff0c\u5b83\u7684\u503c\u6c38\u8fdc\u4e0d\u4f1a\u6539\u53d8\u2014\u2014\u4f46\u662f\u6211\u4eec\u6539\u53d8\u4e86\u4e0a\u9762\u7684\u5e38\u91cf\u6570\u7ec4\u5e76\u6ca1\u6709\u62a5\u9519\u3002\u8fd9\u662f\u4e3a\u4ec0\u4e48\u5462?<\/p>\n<p>\u6ce8\u610f:\u6570\u7ec4\u662f\u5f15\u7528\u7c7b\u578b\uff0c\u800c\u4e0d\u662f JavaScript \u7684\u57fa\u672c\u7c7b\u578b<\/p>\n<p>\u5b9e\u9645\u5b58\u50a8\u5728 arr \u4e2d\u7684\u4e0d\u662f\u6570\u7ec4\uff0c\u800c\u662f\u6570\u7ec4\u5b58\u50a8\u7684\u5185\u5b58\u4f4d\u7f6e\u7684\u5f15\u7528(\u5730\u5740)\u3002\u6267\u884c arr.push(5)\uff0c\u5e76\u6ca1\u6709\u6539\u53d8 arr \u6307\u5411\u7684\u5f15\u7528\uff0c\u800c\u662f\u6539\u53d8\u4e86\u5b58\u50a8\u5728\u90a3\u4e2a\u5f15\u7528\u4e0a\u7684\u503c\u3002<\/p>\n<p>\u5bf9\u8c61\u4e5f\u662f\u5982\u6b64:<\/p>\n<pre><code>const obj = {  name: 'David',  age: 30 };  obj.age = 40;  console.log(obj); \/\/ { name: 'David', age: 40 }  <\/code><\/pre>\n<p>\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u6ca1\u6709\u6539\u53d8 obj \u6307\u5411\u7684\u5f15\u7528\uff0c\u800c\u662f\u6539\u53d8\u4e86\u5b58\u50a8\u5728\u5f15\u7528\u7684\u503c\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u4e0a\u8ff0\u7684\u4ee3\u7801\u5c06\u4f1a\u8d77\u4f5c\u7528\uff0c\u4f46\u4e0b\u9762\u7684\u4ee3\u7801\u662f\u65e0\u6548\u7684\u3002<\/p>\n<pre><code>const obj = { name: 'David', age: 30 }; const obj1 = { name: 'Mike', age: 40 }; obj = obj1; \/\/ Uncaught TypeError: Assignment to constant variable.  <\/code><\/pre>\n<p>\u8fd9\u6837\u5199\u4f1a\u629b\u51fa\u5f02\u5e38\uff0c\u56e0\u4e3a\u6211\u4eec\u8bd5\u56fe\u66f4\u6539 const \u53d8\u91cf\u6307\u5411\u7684\u5f15\u7528\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u5728\u4f7f\u7528 const \u65f6\u8981\u8bb0\u4f4f\u4e00\u70b9\uff1a\u4f7f\u7528 const \u58f0\u660e\u5e38\u91cf\u65f6\uff0c\u4e0d\u80fd\u91cd\u65b0\u58f0\u660e\uff0c\u4e5f\u4e0d\u80fd\u91cd\u65b0\u8d4b\u503c\u3002\u5982\u679c\u58f0\u660e\u7684\u5e38\u91cf\u662f\u5f15\u7528\u7c7b\u578b\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u6539\u5b58\u50a8\u5728\u5f15\u7528\u7684\u503c\u3002<\/p>\n<p>\u540c\u7406\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u4e5f\u662f\u65e0\u6548\u7684\u3002<\/p>\n<pre><code>const arr = [1, 2, 3, 4]; arr = [10, 20, 30]; \/\/ Uncaught TypeError: Assignment to constant variable.  <\/code><\/pre>\n<h4><strong>\u603b\u7ed3\uff1a<\/strong><\/h4>\n<ul>\n<li>\n<p>\u5173\u952e\u5b57 let \u548c const \u5728 JavaScript \u4e2d\u6dfb\u52a0\u5757\u7ea7\u4f5c\u7528\u57df\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f53\u6211\u4eec\u5c06\u4e00\u4e2a\u53d8\u91cf\u58f0\u660e\u4e3a let \u65f6\uff0c\u6211\u4eec\u4e0d\u80fd\u5728\u540c\u4e00\u4f5c\u7528\u57df(\u51fd\u6570\u6216\u5757\u7ea7\u4f5c\u7528\u57df)\u4e2d\u91cd\u65b0\u5b9a\u4e49\u6216\u91cd\u65b0\u58f0\u660e\u53e6\u4e00\u4e2a\u5177\u6709\u76f8\u540c\u540d\u79f0\u7684 let \u53d8\u91cf\uff0c\u4f46\u662f\u6211\u4eec\u53ef\u4ee5\u91cd\u65b0\u8d4b\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f53\u6211\u4eec\u5c06\u4e00\u4e2a\u53d8\u91cf\u58f0\u660e\u4e3a const \u65f6\uff0c\u6211\u4eec\u4e0d\u80fd\u5728\u540c\u4e00\u4f5c\u7528\u57df(\u51fd\u6570\u6216\u5757\u7ea7\u4f5c\u7528\u57df)\u4e2d\u91cd\u65b0\u5b9a\u4e49\u6216\u91cd\u65b0\u58f0\u660e\u5177\u6709\u76f8\u540c\u540d\u79f0\u7684\u53e6\u4e00\u4e2a const \u53d8\u91cf\u3002\u4f46\u662f\uff0c\u5982\u679c\u53d8\u91cf\u662f\u5f15\u7528\u7c7b\u578b(\u5982\u6570\u7ec4\u6216\u5bf9\u8c61)\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u6539\u5b58\u50a8\u5728\u8be5\u53d8\u91cf\u4e2d\u7684\u503c\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u597d\u4e86\uff0c\u6211\u4eec\u7ee7\u7eed\u4e0b\u4e00\u4e2a\u8bdd\u9898: promises \u3002<\/p>\n<h2><strong>JavaScript \u4e2d\u7684 promises<\/strong><\/h2>\n<p>\u5bf9\u4e8e\u5f88\u591a\u65b0\u5f00\u53d1\u8005\u6765\u8bf4\uff0cpromises \u662f JavaScript \u4e2d\u8f83\u96be\u7406\u89e3\u7684\u90e8\u5206\u3002ES6 \u4e2d\u539f\u751f\u63d0\u4f9b\u4e86 Promise \u5bf9\u8c61\uff0c\u90a3\u4e48 Promise \u7a76\u7adf\u662f\u4ec0\u4e48\u5462\uff1f<\/p>\n<p>Promise \u5bf9\u8c61\u4ee3\u8868\u4e86\u672a\u6765\u5c06\u8981\u53d1\u751f\u7684\u4e8b\u4ef6\uff0c\u7528\u6765\u4f20\u9012\u5f02\u6b65\u64cd\u4f5c\u7684\u6d88\u606f\u3002<\/p>\n<p><strong>\u5982\u4f55\u521b\u9020\u4e00\u4e2a promise<\/strong><\/p>\n<p>\u4f7f\u7528 promise \u6784\u9020\u51fd\u6570\u521b\u5efa\u4e00\u4e2a promise\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n<pre><code>const promise = new Promise(function(resolve, reject) {   });  <\/code><\/pre>\n<p>Promise \u7684\u6784\u9020\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u4e14\u5728\u5185\u90e8\u63a5\u6536\u4e24\u4e2a\u53c2\u6570\uff1aresolve\uff0creject \u3002resolve \u548c reject \u53c2\u6570\u5b9e\u9645\u4e0a\u662f\u6211\u4eec\u53ef\u4ee5\u8c03\u7528\u7684\u51fd\u6570\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u5f02\u6b65\u64cd\u4f5c\u7684\u7ed3\u679c\u3002<\/p>\n<p>Promise\u00a0\u6709\u4e09\u79cd\u72b6\u6001:<\/p>\n<ul>\n<li>\n<p>pending: \u521d\u59cb\u72b6\u6001\uff0c\u4e0d\u662f\u6210\u529f\u6216\u5931\u8d25\u72b6\u6001\u3002<\/p>\n<\/li>\n<li>\n<p>fulfilled:\u8868\u793a\u64cd\u4f5c\u6210\u529f\u5b8c\u6210\u3002<\/p>\n<\/li>\n<li>\n<p>rejected: \u8868\u793a\u64cd\u4f5c\u5931\u8d25\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5f53\u6211\u4eec\u521b\u5efa Promise \u65f6\uff0c\u5b83\u5904\u4e8e\u7b49\u5f85\u7684\u72b6\u6001\u3002\u5f53\u6211\u4eec\u8c03\u7528 resolve \u51fd\u6570\u65f6\uff0c\u5b83\u5c06\u8fdb\u5165\u5df2\u5b8c\u6210\u72b6\u6001\u3002\u5982\u679c\u8c03\u7528 reject\uff0c\u4ed6\u5c06\u8fdb\u5165\u88ab\u62d2\u7edd\u72b6\u6001\u3002<\/p>\n<p>\u5728\u4e0b\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u6267\u884c\u4e86\u4e00\u4e2a\u5f02\u6b65\u64cd\u4f5c\uff0c\u4e5f\u5c31\u662f setTimeout\uff0c2 \u79d2\u540e\uff0c\u8c03\u7528 resolve \u65b9\u6cd5\u3002<\/p>\n<pre><code>const promise = new Promise(function(resolve, reject) {  setTimeout(function() {   const sum = 4 + 5;   resolve(sum);  }, 2000); });   <\/code><\/pre>\n<p>\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u6ce8\u518c\u4e00\u4e2a\u56de\u8c03.then \u83b7\u5f97 1promise \u6267\u884c\u6210\u529f\u7684\u7ed3\u679c\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n<pre><code>const promise = new Promise(function(resolve, reject) {  setTimeout(function() {   const sum = 4 + 5;   resolve(sum);  }, 2000); });  promise.then(function(result) {  console.log(result); \/\/ 9 });   <\/code><\/pre>\n<p>then \u63a5\u6536\u4e00\u4e2a\u53c2\u6570\uff0c\u662f\u51fd\u6570\uff0c\u5e76\u4e14\u4f1a\u62ff\u5230\u6211\u4eec\u5728 promise \u4e2d\u8c03\u7528 resolve \u65f6\u4f20\u7684\u7684\u53c2\u6570\u3002<\/p>\n<p>\u5982\u679c\u64cd\u4f5c\u4e0d\u6210\u529f\uff0c\u5219\u8c03\u7528 reject \u51fd\u6570:<\/p>\n<pre><code>const promise = new Promise(function(resolve, reject) {  setTimeout(function() {   const sum = 4 + 5 + 'a';   if(isNaN(sum)) {     reject('Error while calculating sum.');   } else {     resolve(sum);   }  }, 2000); });  promise.then(function(result) {  console.log(result); });   <\/code><\/pre>\n<p>\u5982\u679c sum \u4e0d\u662f\u4e00\u4e2a\u6570\u5b57\uff0c\u90a3\u4e48\u6211\u4eec\u8c03\u7528\u5e26\u6709\u9519\u8bef\u4fe1\u606f\u7684 reject \u51fd\u6570\uff0c\u5426\u5219\u6211\u4eec\u8c03\u7528 resolve \u51fd\u6570\u3002<\/p>\n<p>\u6267\u884c\u4e0a\u8ff0\u4ee3\u7801\uff0c\u8f93\u51fa\u5982\u4e0b:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/12\/20201229_5feb071df40fc.png\" alt=\"\u73b0\u4ee3 JavaScript\uff1a ES6+ \u4e2d\u7684 Imports\uff0c Exports\uff0c Let\uff0c Const \u548c Promise\" \/><\/p>\n<p>\u8c03\u7528 reject \u51fd\u6570\u4f1a\u629b\u51fa\u4e00\u4e2a\u9519\u8bef\uff0c\u4f46\u662f\u6211\u4eec\u6ca1\u6709\u6dfb\u52a0\u7528\u4e8e\u6355\u83b7\u9519\u8bef\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u9700\u8981\u8c03\u7528 catch \u65b9\u6cd5\u6307\u5b9a\u7684\u56de\u8c03\u51fd\u6570\u6765\u6355\u83b7\u5e76\u5904\u7406\u8fd9\u4e2a\u9519\u8bef\u3002<\/p>\n<pre><code>promise.then(function(result) {  console.log(result); }).catch(function(error) {  console.log(error); });  <\/code><\/pre>\n<p>\u8f93\u51fa\u5982\u4e0b:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/12\/20201229_5feb07230ac81.png\" alt=\"\u73b0\u4ee3 JavaScript\uff1a ES6+ \u4e2d\u7684 Imports\uff0c Exports\uff0c Let\uff0c Const \u548c Promise\" \/><\/p>\n<p>\u6240\u4ee5\u5efa\u8bae\u5927\u5bb6\u5728\u4f7f\u7528 promise \u65f6\u52a0\u4e0a catch \u65b9\u6cd5\uff0c\u4ee5\u6b64\u6765\u907f\u514d\u7a0b\u5e8f\u56e0\u9519\u8bef\u800c\u505c\u6b62\u8fd0\u884c\u3002<\/p>\n<p><strong>\u94fe\u5f0f\u64cd\u4f5c<\/strong><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5411\u5355\u4e2a promise \u6dfb\u52a0\u591a\u4e2a then \u65b9\u6cd5\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n<pre><code>promise.then(function(result) {  console.log('first .then handler');  return result; }).then(function(result) {  console.log('second .then handler');  console.log(result); }).catch(function(error) {  console.log(error); });  <\/code><\/pre>\n<p>\u5f53\u6dfb\u52a0\u591a\u4e2a then \u65b9\u6cd5\u65f6\uff0c\u524d\u4e00\u4e2a then \u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u5c06\u81ea\u52a8\u4f20\u9012\u7ed9\u4e0b\u4e00\u4e2a then \u65b9\u6cd5\u3002<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/12\/20201229_5feb07266638b.png\" alt=\"\u73b0\u4ee3 JavaScript\uff1a ES6+ \u4e2d\u7684 Imports\uff0c Exports\uff0c Let\uff0c Const \u548c Promise\" \/><\/p>\n<p>\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u6211\u4eec\u5728\u7b2c\u4e00\u4e2a then \u65b9\u6cd5\u4e2d\u8f93\u51fa\u5b57\u7b26\u4e32\uff0c\u5e76\u5c06\u63a5\u6536\u7684\u53c2\u6570 result \uff08 sum \uff09\u8fd4\u56de\u7ed9\u4e0b\u4e00\u4e2a result \u3002<\/p>\n<p>\u5728\u4e0b\u4e00\u4e2a then \u65b9\u6cd5\u4e2d\uff0c\u8f93\u51fa\u5b57\u7b26\u4e32\uff0c\u5e76\u8f93\u51fa\u4e0a\u4e00\u4e2a then \u65b9\u6cd5\u4f20\u9012\u7ed9\u5b83\u7684 result \u3002<\/p>\n<h4><strong>\u5982\u4f55\u5728 JavaScript \u4e2d\u5ef6\u8fdf promise \u7684\u6267\u884c<\/strong><\/h4>\n<p>\u5f88\u591a\u65f6\u5019\uff0c\u6211\u4eec\u4e0d\u5e0c\u671b\u7acb\u5373\u521b\u5efa promise\uff0c\u800c\u662f\u5e0c\u671b\u5728\u67d0\u4e2a\u64cd\u4f5c\u5b8c\u6210\u540e\u518d\u521b\u5efa\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5c06 promise \u5c01\u88c5\u5728\u4e00\u4e2a\u51fd\u6570\u4e2d\uff0c\u7136\u540e\u4ece\u51fd\u6570\u4e2d\u8fd4\u56de promise\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code>function createPromise() {  return new Promise(function(resolve, reject) {   setTimeout(function() {    const sum = 4 + 5;    if(isNaN(sum)) {      reject('Error while calculating sum.');    } else {     resolve(sum);    }   }, 2000);  }); }   <\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u901a\u8fc7\u51fd\u6570\u5c06\u53c2\u6570\u4f20\u9012\u7ed9 promise\uff0c\u8fbe\u5230\u52a8\u6001\u7684\u76ee\u7684\u3002<\/p>\n<pre><code>function createPromise(a, b) {  return new Promise(function(resolve, reject) {   setTimeout(function() {    const sum = a + b;    if(isNaN(sum)) {      reject('Error while calculating sum.');    } else {     resolve(sum);    }   }, 2000);  }); }  createPromise(1,8)  .then(function(output) {   console.log(output); \/\/ 9 });  \/\/ OR  createPromise(10,24)  .then(function(output) {   console.log(output); \/\/ 34 });  <\/code><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/12\/20201229_5feb072b9de20.png\" alt=\"\u73b0\u4ee3 JavaScript\uff1a ES6+ \u4e2d\u7684 Imports\uff0c Exports\uff0c Let\uff0c Const \u548c Promise\" \/><\/p>\n<p>\u6b64\u5916\uff0c\u6211\u4eec\u53ea\u80fd\u5411 resolve \u6216 reject \u51fd\u6570\u4f20\u9012\u4e00\u4e2a\u503c\u3002\u5982\u679c\u4f60\u60f3\u4f20\u9012\u591a\u4e2a\u503c\u5230 resolve \u51fd\u6570\uff0c\u53ef\u4ee5\u5c06\u5b83\u4f5c\u4e3a\u4e00\u4e2a\u5bf9\u8c61\u4f20\u9012\uff0c\u5982\u4e0b:<\/p>\n<pre><code>const promise = new Promise(function(resolve, reject) {  setTimeout(function() {   const sum = 4 + 5;   resolve({    a: 4,    b: 5,    sum   });  }, 2000); });  promise.then(function(result) {  console.log(result); }).catch(function(error) {  console.log(error); });  <\/code><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" referrerpolicy=\"no-referrer\" rel=\"noreferrer\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/12\/20201229_5feb072ecaae4.png\" alt=\"\u73b0\u4ee3 JavaScript\uff1a ES6+ \u4e2d\u7684 Imports\uff0c Exports\uff0c Let\uff0c Const \u548c Promise\" \/><\/p>\n<h4><strong>\u5982\u4f55\u5728 JavaScript \u4e2d\u4f7f\u7528\u7bad\u5934\u51fd\u6570<\/strong><\/h4>\n<p>\u4e0a\u8ff0\u793a\u4f8b\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u5e38\u89c4\u7684 ES5 \u8bed\u6cd5\u521b\u5efa\u4e86 promise \u3002\u4f46\u662f\uff0c\u901a\u5e38\u4f7f\u7528\u7bad\u5934\u51fd\u6570\u4ee3\u66ff ES5 \u8bed\u6cd5\uff0c\u5982\u4e0b:<\/p>\n<pre><code>const promise = new Promise((resolve, reject) =&gt; {  setTimeout(() =&gt; {   const sum = 4 + 5 + 'a';   if(isNaN(sum)) {     reject('Error while calculating sum.');   } else {     resolve(sum);   }  }, 2000); });  promise.then((result) =&gt; {  console.log(result); });  <\/code><\/pre>\n<p>\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u9700\u8981\u4f7f\u7528 ES5 \u6216 ES6 \u8bed\u6cd5\u3002<\/p>\n<h4><strong>ES6 Import \u548c Export \u8bed\u6cd5<\/strong><\/h4>\n<p>\u5728 ES6 \u4e4b\u524d\uff0c\u6211\u4eec\u5728\u4e00\u4e2a HTML \u6587\u4ef6\u4e2d\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a script \u6807\u7b7e\u6765\u5f15\u7528\u4e0d\u540c\u7684 JavaScript \u6587\u4ef6\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n<pre><code>&lt;script type=\"text\/javascript\" src=\"home.js\"&gt;&lt;\/script&gt; &lt;script type=\"text\/javascript\" src=\"profile.js\"&gt;&lt;\/script&gt; &lt;script type=\"text\/javascript\" src=\"user.js\"&gt;&lt;\/script&gt;  <\/code><\/pre>\n<p>\u4f46\u662f\u5982\u679c\u6211\u4eec\u5728\u4e0d\u540c\u7684 JavaScript \u6587\u4ef6\u4e2d\u6709\u4e00\u4e2a\u540c\u540d\u7684\u53d8\u91cf\uff0c\u5c06\u4f1a\u51fa\u73b0\u547d\u540d\u51b2\u7a81\uff0c\u4f60\u5b9e\u9645\u5f97\u5230\u7684\u53ef\u80fd\u5e76\u4e0d\u662f\u4f60\u671f\u671b\u7684\u503c\u3002<\/p>\n<p>ES6 \u589e\u52a0\u4e86\u6a21\u5757\u7684\u6982\u5ff5\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p>\u5728 ES6 \u4e2d\uff0c\u6211\u4eec\u7f16\u5199\u7684\u6bcf\u4e00\u4e2a JavaScript \u6587\u4ef6\u90fd\u88ab\u79f0\u4e3a\u6a21\u5757\u3002\u6211\u4eec\u5728\u6bcf\u4e2a\u6587\u4ef6\u4e2d\u58f0\u660e\u7684\u53d8\u91cf\u548c\u51fd\u6570\u4e0d\u80fd\u7528\u4e8e\u5176\u4ed6\u6587\u4ef6\uff0c\u9664\u975e\u6211\u4eec\u5c06\u5b83\u4eec\u4ece\u8be5\u6587\u4ef6\u4e2d\u5bfc\u51fa\u5e76\u3001\u5728\u53e6\u4e00\u4e2a\u6587\u4ef6\u4e2d\u5f97\u5230\u5f15\u7528\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u5728\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\u51fd\u6570\u548c\u53d8\u91cf\u662f\u6bcf\u4e2a\u6587\u4ef6\u79c1\u6709\u7684\uff0c\u5728\u5bfc\u51fa\u5b83\u4eec\u4e4b\u524d\uff0c\u4e0d\u80fd\u5728\u6587\u4ef6\u5916\u90e8\u8bbf\u95ee\u5b83\u4eec\u3002<\/p>\n<p>export \u6709\u4e24\u79cd\u7c7b\u578b:<\/p>\n<ul>\n<li>\n<p>\u547d\u540d\u5bfc\u51fa:\u5728\u4e00\u4e2a\u6587\u4ef6\u4e2d\u53ef\u4ee5\u6709\u591a\u4e2a\u547d\u540d\u5bfc\u51fa<\/p>\n<\/li>\n<li>\n<p>\u9ed8\u8ba4\u5bfc\u51fa:\u5355\u4e2a\u6587\u4ef6\u4e2d\u53ea\u80fd\u6709\u4e00\u4e2a\u9ed8\u8ba4\u5bfc\u51fa<\/p>\n<\/li>\n<\/ul>\n<h4><strong>JavaScript \u4e2d\u7684\u547d\u540d\u5bfc\u51fa<\/strong><\/h4>\n<p>\u5982\u4e0b\u6240\u793a\uff0c\u5c06\u5355\u4e2a\u53d8\u91cf\u547d\u540d\u5bfc\u51fa:<\/p>\n<pre><code>export const temp = \"This is some dummy text\"; <\/code><\/pre>\n<p>\u5982\u679c\u60f3\u5bfc\u51fa\u591a\u4e2a\u53d8\u91cf\uff0c\u53ef\u4ee5\u4f7f\u7528\u5927\u62ec\u53f7\u6307\u5b9a\u8981\u8f93\u51fa\u7684\u4e00\u7ec4\u53d8\u91cf\u3002<\/p>\n<pre><code>const temp1 = \"This is some dummy text1\"; const temp2 = \"This is some dummy text2\"; export { temp1, temp2 };  <\/code><\/pre>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5bfc\u51fa\u8bed\u6cd5\u4e0d\u662f\u5bf9\u8c61\u8bed\u6cd5\u3002\u56e0\u6b64\uff0c\u5728 ES6 \u4e2d\uff0c\u4e0d\u80fd\u4f7f\u7528\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\u5bfc\u51fa\u3002<\/p>\n<pre><code>          \/\/ This is invalid syntax of export in ES6            export { key1: value1, key2: value2 }  <\/code><\/pre>\n<p>import \u547d\u4ee4\u63a5\u53d7\u4e00\u5bf9\u5927\u62ec\u53f7\uff0c\u91cc\u9762\u6307\u5b9a\u8981\u4ece\u5176\u4ed6\u6a21\u5757\u5bfc\u5165\u7684\u53d8\u91cf\u540d\u3002<\/p>\n<pre><code>           import { temp1, temp2 } from '.\/filename'; <\/code><\/pre>\n<p>\u6ce8\u610f\uff0c\u4e0d\u9700\u8981\u5728\u6587\u4ef6\u540d\u4e2d\u6dfb\u52a0.js \u6269\u5c55\u540d\uff0c\u56e0\u4e3a\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f1a\u8003\u8651\u8be5\u62d3\u5c55\u540d\u3002<\/p>\n<pre><code>  \/\/ import from functions.js file from current directory  import  { temp1, temp2 }  from  '.\/functions';   \/\/ import from functions.js file from parent of current directory  import  { temp1 }  from  '..\/functions'; <\/code><\/pre>\n<p>\u63d0\u793a\u4e00\u70b9\uff0c\u5bfc\u5165\u7684\u53d8\u91cf\u540d\u5fc5\u987b\u4e0e\u88ab\u5bfc\u5165\u6a21\u5757\u5bf9\u5916\u63a5\u53e3\u7684\u540d\u79f0\u76f8\u540c\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u5bfc\u51fa\u5e94\u4f7f\u7528\uff1a<\/p>\n<pre><code>\/\/ constants.js  export  const  PI  =  3.14159; <\/code><\/pre>\n<p>\u90a3\u4e48\u5728\u5bfc\u5165\u7684\u65f6\u5019\uff0c\u5fc5\u987b\u4f7f\u7528\u4e0e\u5bfc\u51fa\u65f6\u76f8\u540c\u7684\u540d\u79f0\uff1a<\/p>\n<pre><code>import  {  PI  }  from  '.\/constants';  \/\/ This will throw an error  import  { PiValue }  from  '.\/constants'; <\/code><\/pre>\n<p>\u5982\u679c\u60f3\u4e3a\u8f93\u5165\u7684\u53d8\u91cf\u91cd\u65b0\u547d\u540d\uff0c\u53ef\u4ee5\u4f7f\u7528 as \u5173\u952e\u5b57\uff0c\u8bed\u6cd5\u5982\u4e0b:<\/p>\n<pre><code>import  {  PI  as PIValue }  from  '.\/constants'; <\/code><\/pre>\n<p>\u6211\u4eec\u4ee5\u4e3a PI \u91cd\u547d\u540d\u4e3a PIValue\uff0c\u56e0\u6b64\u4e0d\u80fd\u518d\u4f7f\u7528 PI \u53d8\u91cf\u540d\u3002<\/p>\n<p>\u5bfc\u51fa\u65f6\u4e5f\u53ef\u4f7f\u7528\u4e0b\u9762\u7684\u91cd\u547d\u540d\u8bed\u6cd5\uff1a<\/p>\n<pre><code>\/\/ constants.js  const  PI  =  3.14159;  export  {  PI  as PIValue }; <\/code><\/pre>\n<p>\u7136\u540e\u5728\u5bfc\u5165\u662f\uff0c\u5fc5\u987b\u4f7f\u7528 PIValue \u3002<\/p>\n<pre><code>import  { PIValue }  from  '.\/constants'; <\/code><\/pre>\n<p>\u547d\u540d\u5bfc\u51fa\u67d0\u4e9b\u5185\u5bb9\u4e4b\u524d\u5fc5\u987b\u5148\u58f0\u660e\u5b83\u3002<\/p>\n<pre><code>export  'hello';  \/\/ this will result in error  export  const greeting =  'hello';  \/\/ this will work  export  { name:  'David'  };  \/\/ This will result in error  export  const object =  { name:  'David'  };  \/\/ This will work <\/code><\/pre>\n<p>\u6211\u4eec\u6765\u770b\u4e0b\u9762\u7684 validations.js \u6587\u4ef6:<\/p>\n<pre><code>\/\/ utils\/validations.js  const  isValidEmail  =  function(email)  {    if  (\/^[^@ ][email&#160;protected][^@ ]+.[^@ .]{2,}$\/.test(email))  {    return  \"email is valid\";    }  else  {    return  \"email is invalid\";    }  };  const  isValidPhone  =  function(phone)  {    if  (\/^[\\(]d{3}[\\)]sd{3}-d{4}$\/.test(phone))  {    return  \"phone number is valid\";    }  else  {    return  \"phone number is invalid\";    }  };  function  isEmpty(value)  {    if  (\/^s*$\/.test(value))  {    return  \"string is empty or contains only spaces\";    }  else  {    return  \"string is not empty and does not contain spaces\";    }  }  export  { isValidEmail, isValidPhone, isEmpty }; <\/code><\/pre>\n<p>\u5728 index.js \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u51fd\u6570:<\/p>\n<pre><code>\/\/ index.js  import  { isEmpty, isValidEmail }  from  \".\/utils\/validations\";  console.log(\"isEmpty:\",  isEmpty(\"abcd\"));  \/\/ isEmpty: string is not empty and does not contain spaces  console.log(\"isValidEmail:\",  isValidEmail(\"[email&#160;protected]\"));  \/\/ isValidEmail: email is valid  console.log(\"isValidEmail:\",  isValidEmail(\"[email&#160;protected]@11gmail.com\"));  \/\/ isValidEmail: email is invalid <\/code><\/pre>\n<h4><strong>JavaScript \u7684\u9ed8\u8ba4\u5bfc\u51fa<\/strong><\/h4>\n<p>\u5982\u4e0a\u6240\u8ff0\uff0c\u5355\u4e2a\u6587\u4ef6\u4e2d\u6700\u591a\u53ea\u80fd\u6709\u4e00\u4e2a\u9ed8\u8ba4\u5bfc\u51fa\u3002\u4f46\u662f\uff0c\u4f60\u53ef\u4ee5\u5728\u4e00\u4e2a\u6587\u4ef6\u4e2d\u4f7f\u7528\u591a\u4e2a\u547d\u540d\u5bfc\u51fa\u548c\u4e00\u4e2a\u9ed8\u8ba4\u5bfc\u51fa\u3002<\/p>\n<p>\u8981\u58f0\u660e\u4e00\u4e2a\u9ed8\u8ba4\u5bfc\u51fa\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre><code>\/\/constants.js  const name =  'David';  export  default name; <\/code><\/pre>\n<p>\u5728\u5bfc\u5165\u65f6\u5c31\u4e0d\u9700\u8981\u518d\u4f7f\u7528\u82b1\u62ec\u53f7\u4e86\u3002<\/p>\n<pre><code>import name from  '.\/constants'; <\/code><\/pre>\n<p>\u5982\u4e0b\uff0c\u6211\u4eec\u6709\u591a\u4e2a\u547d\u540d\u5bfc\u51fa\u548c\u4e00\u4e2a\u9ed8\u8ba4\u5bfc\u51fa:<\/p>\n<pre><code>\/\/ constants.js  export  const  PI  =  3.14159;  export  const  AGE  =  30;  const  NAME  =  \"David\";  export  default  NAME; <\/code><\/pre>\n<p>\u6b64\u65f6\u6211\u4eec\u4f7f\u7528 import \u5bfc\u5165\u65f6\uff0c\u53ea\u9700\u8981\u5728\u5927\u62ec\u53f7\u4e4b\u524d\u6307\u5b9a\u9ed8\u8ba4\u5bfc\u51fa\u7684\u53d8\u91cf\u540d\u3002<\/p>\n<pre><code>\/\/ NAME is default export and PI and AGE are named exports here  import  NAME,  {  PI,  AGE  }  from  '.\/constants'; <\/code><\/pre>\n<p>\u4f7f\u7528 export default \u5bfc\u51fa\u7684\u5185\u5bb9\uff0c\u5728\u5bfc\u5165\u7684\u65f6\u5019\uff0cimport \u540e\u9762\u7684\u540d\u79f0\u53ef\u4ee5\u662f\u4efb\u610f\u7684\u3002<\/p>\n<pre><code>\/\/ constants.js  const  AGE  =  30;  export  default  AGE;  import myAge from \u2018.\/constants\u2019;  console.log(myAge);  \/\/ 30 <\/code><\/pre>\n<p>\u53e6\u5916\uff0cexport default \u7684\u53d8\u91cf\u540d\u79f0\u4ece Age \u5230 myAge \u4e4b\u6240\u4ee5\u53ef\u884c\uff0c\u662f\u56e0\u4e3a\u53ea\u80fd\u5b58\u5728\u4e00\u4e2a export default \u3002\u56e0\u6b64\u4f60\u53ef\u4ee5\u968f\u610f\u547d\u540d\u3002\u8fd8\u9700\u6ce8\u610f\u7684\u662f\uff0c\u5173\u952e\u5b57\u4e0d\u80fd\u5728\u58f0\u660e\u53d8\u91cf\u4e4b\u524d\u3002<\/p>\n<pre><code>\/\/ constants.js  export  default  const  AGE  =  30;  \/\/ This is an error and will not work <\/code><\/pre>\n<p>\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u5728\u5355\u72ec\u7684\u4e00\u884c\u4f7f\u7528\u5173\u952e\u5b57\u3002<\/p>\n<pre><code>\/\/ constants.js  const  AGE  =  30;  export  default  AGE; <\/code><\/pre>\n<p>\u4e0d\u8fc7\u4ee5\u4e0b\u5f62\u5f0f\u662f\u5141\u8bb8\u7684:<\/p>\n<pre><code>\/\/constants.js  export  default  {  \u00a0name:  \"Billy\",  \u00a0age:  40  }; <\/code><\/pre>\n<p>\u5e76\u4e14\u9700\u8981\u5728\u53e6\u4e00\u4e2a\u6587\u4ef6\u4e2d\u4f7f\u7528\u5b83<\/p>\n<pre><code>import user from  '.\/constants';  console.log(user.name);  \/\/ Billy  console.log(user.age);  \/\/ 40 <\/code><\/pre>\n<p>\u8fd8\u6709\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u6765\u5bfc\u5165 constants.js \u6587\u4ef6\u4e2d\u5bfc\u51fa\u7684\u6240\u6709\u53d8\u91cf:<\/p>\n<pre><code>\/\/ test.js  import  *  as constants from  '.\/constants'; <\/code><\/pre>\n<p>\u4e0b\u9762\uff0c\u6211\u4eec\u5c06\u5bfc\u5165\u6240\u6709\u6211\u4eec constants.js \u5b58\u50a8\u5728 constants \u53d8\u91cf\u4e2d\u7684\u547d\u540d\u548c export default \u3002\u56e0\u6b64\uff0cconstants \u73b0\u5728\u5c06\u6210\u4e3a\u5bf9\u8c61\u3002<\/p>\n<pre><code>\/\/ constants.js  export  const  USERNAME  =  \"David\";  export  default  {  \u00a0name:  \"Billy\",  \u00a0age:  40  }; <\/code><\/pre>\n<p>\u5728\u53e6\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u6309\u4e00\u4e0b\u65b9\u5f0f\u4f7f\u7528\u3002<\/p>\n<pre><code>\/\/ test.js  import  *  as constants from  '.\/constants';  console.log(constants.USERNAME);  \/\/ David  console.log(constants.default);  \/\/ { name: \"Billy\", age: 40 }  console.log(constants.default.age);  \/\/ 40 <\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u5f0f\u7ec4\u5408\u4f7f\u7528\u547d\u540d\u5bfc\u51fa\u548c\u9ed8\u8ba4\u5bfc\u51fa:<\/p>\n<pre><code>\/\/ constants.js  const  PI  =  3.14159;  const  AGE  =  30;  const  USERNAME  =  \"David\";  const  USER  =  {  \u00a0name:  \"Billy\",  \u00a0age:  40  };  export  {  PI,  AGE,  USERNAME,  USER  as  default  };  import  USER,  {  PI,  AGE,  USERNAME  }  from  \".\/constants\"; <\/code><\/pre>\n<p>\u603b\u800c\u8a00\u4e4b:<\/p>\n<p>ES6 \u4e2d\uff0c\u4e00\u4e2a\u6a21\u5757\u5c31\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u6587\u4ef6\uff0c\u8be5\u6587\u4ef6\u5185\u90e8\u7684\u6240\u6709\u53d8\u91cf\uff0c\u5916\u90e8\u90fd\u65e0\u6cd5\u83b7\u53d6\u3002\u5982\u679c\u60f3\u4ece\u5916\u90e8\u8bfb\u53d6\u6a21\u5757\u5185\u7684\u67d0\u4e2a\u53d8\u91cf\uff0c\u5fc5\u987b\u4f7f\u7528 export \u5173\u952e\u5b57\u5bfc\u51fa\u8be5\u53d8\u91cf\uff0c\u4f7f\u7528 import \u5173\u952e\u5b57\u5bfc\u5165\u8be5\u53d8\u91cf\u3002<\/p>\n<h2><strong>JavaScript \u4e2d\u7684\u9ed8\u8ba4\u53c2\u6570<\/strong><\/h2>\n<p>ES6 \u589e\u52a0\u4e86\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u7279\u6027\uff0c\u5373\u5728\u5b9a\u4e49\u51fd\u6570\u65f6\u63d0\u4f9b\u9ed8\u8ba4\u53c2\u6570\u3002<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u4e00\u65e6\u7528\u6237\u767b\u5f55\u7cfb\u7edf\uff0c\u6211\u4eec\u5c06\u5411\u4ed6\u4eec\u663e\u793a\u4e00\u6761\u6b22\u8fce\u6d88\u606f\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n<pre><code>function  showMessage(firstName)  {    return  \"Welcome back, \"  + firstName;  }  console.log(showMessage('John'));  \/\/ Welcome back, John <\/code><\/pre>\n<p>\u4f46\u662f\uff0c\u5982\u679c\u6570\u636e\u5e93\u4e2d\u6ca1\u6709\u7528\u6237\u540d\uff0c\u90a3\u8be5\u600e\u4e48\u529e\u5462?\u6240\u4ee5\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u68c0\u67e5\u662f\u5426\u63d0\u4f9b\u4e86 firstName\uff0c\u7136\u540e\u518d\u663e\u793a\u76f8\u5e94\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u5728 ES6 \u4e4b\u524d\uff0c\u6211\u4eec\u5fc5\u987b\u5199\u8fd9\u6837\u7684\u4ee3\u7801:<\/p>\n<pre><code>function  showMessage(firstName)  {    if(firstName)  {    return  \"Welcome back, \"  + firstName;    }  else  {    return  \"Welcome back, Guest\";    }  }  console.log(showMessage('John'));  \/\/ Welcome back, John  console.log(showMessage());  \/\/ Welcome back, Guest <\/code><\/pre>\n<p>\u4f46\u73b0\u5728\u4f7f\u7528 ES6 \u63d0\u4f9b\u7684\u9ed8\u8ba4\u53c2\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd9\u6837\u5199:<\/p>\n<pre><code>function  showMessage(firstName =  'Guest')  {    return  \"Welcome back, \"  + firstName;  }  console.log(showMessage('John'));  \/\/ Welcome back, John  console.log(showMessage());  \/\/ Welcome back, Guest <\/code><\/pre>\n<p>\u51fd\u6570\u7684\u9ed8\u8ba4\u53c2\u6570\u53ef\u4ee5\u4e3a\u4efb\u610f\u503c\u3002<\/p>\n<pre><code>function  display(a =  10, b =  20, c = b)  {  \u00a0console.log(a, b, c);  }  display();  \/\/ 10 20 20  display(40);  \/\/ 40 20 20  display(1,  70);  \/\/ 1 70 70  display(1,  30,  70);  \/\/ 1 30 70 <\/code><\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u6ca1\u6709\u63d0\u4f9b\u51fd\u6570\u7684\u6240\u6709\u53c2\u6570\uff0c\u5b9e\u9645\u4ee3\u7801\u7b49\u540c\u4e8e:<\/p>\n<pre><code>display();  \/\/ \u7b49\u540c\u4e8e display(undefined, undefined, undefined)  display(40);  \u7b49\u540c\u4e8e display(40, undefined, undefined)  display(1,  70);  \u7b49\u540c\u4e8e display(1, 70, undefined) <\/code><\/pre>\n<p>\u56e0\u6b64\uff0c\u5982\u679c\u4f20\u9012\u7684\u53c2\u6570\u662f undefined\uff0c\u5219\u5bf9\u5e94\u7684\u53c2\u6570\u5c06\u4f7f\u7528\u9ed8\u8ba4\u503c\u3002<\/p>\n<p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u5c06\u5bf9\u8c61\u6216\u8ba1\u7b97\u503c\u6307\u5b9a\u4e3a\u9ed8\u8ba4\u503c\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre><code>const defaultUser =  {   name:  'Jane',   location:  'NY',   job:  'Software Developer'  };  const  display  =  (user = defaultUser, age =  60  \/  2  )  =&gt;  {  \u00a0console.log(user, age);  };  display();  \/* output  {   name: 'Jane',   location: 'NY',   job: 'Software Developer'  } 30  *\/ <\/code><\/pre>\n<p>ES5 \u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre><code>\/\/ ES5 Code  function  getUsers(page, results, gender, nationality)  {    var params =  \"\";    if(page ===  0  || page)  {   params +=  `page=${page}&amp;`;    }    if(results)  {   params +=  `results=${results}&amp;`;    }    if(gender)  {   params +=  `gender=${gender}&amp;`;    }    if(nationality)  {   params +=  `nationality=${nationality}`;    }    fetch('https:\/\/randomuser.me\/api\/?'  + params)    .then(function(response)  {    return response.json();    })    .then(function(result)  {   console.log(result);    })    .catch(function(error)  {   console.log('error', error);    });  }  getUsers(0,  10,  'male',  'us'); <\/code><\/pre>\n<p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u5728 getUsers \u51fd\u6570\u4e2d\u4f20\u9012\u5404\u79cd\u53ef\u9009\u53c2\u6570\u6765\u8fdb\u884c API \u8c03\u7528\u3002\u5728\u8fdb\u884c API \u8c03\u7528\u4e4b\u524d\uff0c\u6211\u4eec\u6dfb\u52a0\u4e86\u5404\u79cd if \u6761\u4ef6\u6765\u68c0\u67e5\u662f\u5426\u6dfb\u52a0\u4e86\u53c2\u6570\uff0c\u5e76\u57fa\u4e8e\u6b64\u6784\u9020\u67e5\u8be2\u5b57\u7b26\u4e32\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre><code>https:\/\/randomuser.me\/api\/? page=0&amp;results=10&amp;gender=male&amp;nationality=us <\/code><\/pre>\n<p>\u4f7f\u7528 ES6 \u7684\u9ed8\u8ba4\u53c2\u6570\u5219\u4e0d\u5fc5\u6dfb\u8fd9\u4e48\u591a if \u6761\u4ef6\uff0c\u5982\u4e0b\u6240\u793a:<\/p>\n<pre><code>function  getUsers(page =  0, results =  10, gender =  'male',nationality =  'us')  {  \u00a0fetch(`https:\/\/randomuser.me\/api\/?page=${page}&amp;results=${results}&amp;gender=${gender}&amp;nationality=${nationality}`)  \u00a0.then(function(response)  {    return response.json();  \u00a0})  \u00a0.then(function(result)  {   console.log(result);  \u00a0})  \u00a0.catch(function(error)  {   console.log('error', error);    });  }  getUsers(); <\/code><\/pre>\n<p>\u8fd9\u6837\u4e00\u6765\uff0c\u4ee3\u7801\u5f97\u5230\u4e86\u5927\u91cf\u7684\u7b80\u5316\uff0c\u5373\u4fbf\u6211\u4eec\u4e0d\u4e3a getUsers \u51fd\u6570\u63d0\u4f9b\u4efb\u4f55\u53c2\u6570\u65f6\uff0c\u5b83\u4e5f\u80fd\u91c7\u7528\u9ed8\u8ba4\u503c\u3002\u5f53\u7136\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f20\u9012\u81ea\u5df1\u7684\u53c2\u6570\uff1a<\/p>\n<pre><code>getUsers(1,  20,  'female',  'gb'); <\/code><\/pre>\n<p>\u5b83\u5c06\u8986\u76d6\u51fd\u6570\u7684\u9ed8\u8ba4\u53c2\u6570\u3002<\/p>\n<h2><strong>null \u4e0d\u7b49\u4e8e\u672a\u5b9a\u4e49<\/strong><\/h2>\n<p>\u6ce8\u610f: \u5b9a\u4e49\u9ed8\u8ba4\u53c2\u6570\u65f6\uff0cnull \u548c undefined \u662f\u4e0d\u540c\u7684\u3002<\/p>\n<p>\u6211\u4eec\u6765\u770b\u4e0b\u9762\u7684\u4ee3\u7801:<\/p>\n<pre><code>function  display(name =  'David', age =  35, location =  'NY'){  \u00a0console.log(name, age, location);  }  display('David',  35);  \/\/ David 35 NY  display('David',  35,  undefined);  \/\/ David 35 NY  \/\/ OR  display('David',  35,  undefined);  \/\/ David 35 NY  display('David',  35,  null);  \/\/ David 35 null  <\/code><\/pre>\n<p>\u5f53\u6211\u4eec\u4f20\u9012 null \u4f5c\u4e3a\u53c2\u6570\u65f6\uff0c\u5b83\u5b9e\u9645\u662f\u7ed9 location \u53c2\u6570\u8d4b\u4e00\u4e2a\u7a7a\u503c\uff0c\u4e0e undefined \u4e0d\u4e00\u6837\u3002\u6240\u4ee5\u5b83\u4e0d\u4f1a\u53d6\u9ed8\u8ba4\u503c\u201cNY\u201d\u3002<\/p>\n<h4><strong>Array.prototype.includes<\/strong><\/h4>\n<p>ES7 \u589e\u52a0\u4e86\u6570\u7ec4\u7684 includes \u65b9\u6cd5\uff0c\u7528\u6765\u5224\u65ad\u4e00\u4e2a\u6570\u7ec4\u662f\u5426\u5305\u542b\u4e00\u4e2a\u6307\u5b9a\u7684\u503c\uff0c\u5982\u679c\u662f\u8fd4\u56de true\uff0c\u5426\u5219 false \u3002<\/p>\n<pre><code>\/\/ ES5 Code const numbers = [\"one\", \"two\", \"three\", \"four\"]; console.log(numbers.indexOf(\"one\") &gt; -1); \/\/ true  console.log(numbers.indexOf(\"five\") &gt; -1); \/\/ false  <\/code><\/pre>\n<p>\u6570\u7ec4\u53ef\u4ee5\u4f7f\u7528 includes \u65b9\u6cd5:<\/p>\n<pre><code>\/\/ ES7 Code  const numbers =  [\"one\",  \"two\",  \"three\",  \"four\"];  console.log(numbers.includes(\"one\"));  \/\/ true  console.log(numbers.includes(\"five\"));  \/\/ false <\/code><\/pre>\n<p>includes \u65b9\u6cd5\u53ef\u4ee5\u4f7f\u4ee3\u7801\u7b80\u77ed\u4e14\u6613\u4e8e\u7406\u89e3\uff0c\u5b83\u4e5f\u53ef\u7528\u4e8e\u6bd4\u8f83\u4e0d\u540c\u7684\u503c\u3002<\/p>\n<pre><code>&lt;pre style=\"line-height:18.0pt; vertical-align:baseline\"&gt;const day =  \"monday\";&lt;\/pre&gt;  if(day ===  \"monday\"  || day ===  \"tuesday\"  || day ===  \"wednesday\")  {    \/\/ do something  }  \/\/ \u4ee5\u4e0a\u4ee3\u7801\u4f7f\u7528 include \u65b9\u6cd5\u53ef\u4ee5\u7b80\u5316\u5982\u4e0b:  const day =  \"monday\";  if([\"monday\",  \"tuesday\",  \"wednesday\"].includes(day))  {    \/\/ do something  } <\/code><\/pre>\n<p>\u56e0\u6b64\uff0c\u5728\u68c0\u67e5\u6570\u7ec4\u4e2d\u7684\u503c\u65f6\uff0c\u4f7f\u7528 includes \u65b9\u6cd5\u5c06\u4f1a\u975e\u5e38\u7684\u65b9\u4fbf\u3002<\/p>\n<h2><strong>\u7ed3\u8bed<\/strong><\/h2>\n<p>\u4ece ES6 \u5f00\u59cb\uff0cJavaScript \u4e2d\u53d1\u751f\u8bb8\u591a\u53d8\u66f4\u3002\u5bf9\u4e8e JavaScript\uff0cAngular\uff0cReact \u6216 Vue \u5f00\u53d1\u4eba\u5458\u90fd\u5e94\u8be5\u77e5\u9053\u5b83\u4eec\u3002<\/p>\n<p>\u4e86\u89e3\u8fd9\u4e9b\u53d8\u66f4\u53ef\u4ee5\u4f7f\u4f60\u6210\u4e3a\u66f4\u68d2\u7684\u5f00\u53d1\u8005\uff0c\u751a\u81f3\u53ef\u4ee5\u5e2e\u52a9\u60a8\u83b7\u5f97\u66f4\u9ad8\u7684\u85aa\u6c34\u3002\u800c\u4e14\uff0c\u5982\u679c\u4f60\u53ea\u662f\u5728\u5b66\u4e60 React \u4e4b\u7c7b\u7684\u5e93\u4ee5\u53ca Angular \u548c Vue \u4e4b\u7c7b\u7684\u6846\u67b6\uff0c\u90a3\u4e48\u60a8\u4e00\u5b9a\u8981\u638c\u63e1\u8fd9\u4e9b\u65b0\u7279\u6027\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4703494\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : GrapeCityChina <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u81ea\u9876\uff0c\u987a\u4fbf\u6253\u4e2a\u5e7f\u544a\uff1a<\/p>\n<p>\u5173\u4e8e ES 6\uff0c\u9664\u4e86\u8bed\u6cd5\u66f4\u65b0\u9700\u8981\u4e86\u89e3\uff0c\u5f00\u53d1\u8005\u8fd8\u9700\u638c\u63e1\u4e00\u4e9b\u7b2c\u4e09\u65b9\u7ec4\u4ef6\uff0c\u4ee5\u4fbf\u66f4\u597d\u7684\u5b8c\u6210\u9879\u76ee\u4ea4\u4ed8\u3002<br \/>\u4f8b\u5982\uff0c\u4f7f\u7528 SpreadJS \u8868\u683c\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u5411 JavaScript \u5e94\u7528\u7a0b\u5e8f\u6dfb\u52a0\u9ad8\u7ea7\u7535\u5b50\u8868\u683c\u529f\u80fd\uff0c\u5305\u62ec\u652f\u6301 450 \u591a\u79cd\u8ba1\u7b97\u516c\u5f0f\u3001\u5728\u7ebf\u5bfc\u5165\u5bfc\u51fa Excel \u6587\u6863\u3001\u6570\u636e\u900f\u89c6\u8868\u548c\u53ef\u89c6\u5316\u5206\u6790\uff0c\u4ee5\u521b\u5efa\u8d22\u52a1\u3001\u5206\u6790\u3001\u9884\u7b97 \/\u9884\u6d4b\u3001\u6570\u636e\u6536\u96c6\u3001\u79d1\u5b66\u548c\u8bb8\u591a\u5176\u4ed6\u7c7b\u4f3c\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>SpreadJS \u8868\u683c\u7ec4\u4ef6\u5730\u5740\uff1a https:\/\/www.grapecity.com.cn\/developer\/spreadjs                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4703495\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : HFX3389 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u597d\u957f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4703496\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : gqbre <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5bfc\u5165\u5bfc\u51fa\u90a3\u5757\u4e0d\u9519                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4703497\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tiglapiles <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u518d\u52a0\u4e00\u4e2a Proxy                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4703498\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hantsy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             generaters, class \u4e5f\u662f\u6700\u65b0 ES \u7279\u6027\uff0c\u6211\u5b9e\u5728\u770b\u5230 Generaters \u6655\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4703499\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : guansixu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8d5e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4703500\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : agee <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7b80\u5355\u660e\u4e86\uff0c\u8d5e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u73b0\u4ee3 JavaScript\uff1a ES&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/229430"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=229430"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/229430\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=229430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=229430"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=229430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}