{"id":2439,"date":"2024-11-10T10:55:41","date_gmt":"2024-11-10T02:55:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2439\/"},"modified":"2024-11-10T10:55:41","modified_gmt":"2024-11-10T02:55:41","slug":"ecmascript-%e4%b8%ad%e6%94%b9%e5%8f%98%e4%b8%96%e7%95%8c%e7%9a%84-javascript-%e5%8a%9f%e8%83%bd%e4%bb%a5%e5%89%8d%e6%89%80%e6%9c%aa%e6%9c%89%e7%9a%84%e6%96%b9%e5%bc%8f%e6%8f%90%e5%8d%87%e6%82%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2439\/","title":{"rendered":"ECMAScript \u4e2d\u6539\u53d8\u4e16\u754c\u7684 JavaScript \u529f\u80fd\u4ee5\u524d\u6240\u672a\u6709\u7684\u65b9\u5f0f\u63d0\u5347\u60a8\u7684\u4ee3\u7801\uff01"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173076660492992.jpg\" class=\"aligncenter\" title=\"ECMAScript \u4e2d\u6539\u53d8\u4e16\u754c\u7684 JavaScript \u529f\u80fd\u4ee5\u524d\u6240\u672a\u6709\u7684\u65b9\u5f0f\u63d0\u5347\u60a8\u7684\u4ee3\u7801\uff01\u63d2\u56fe\" alt=\"ECMAScript \u4e2d\u6539\u53d8\u4e16\u754c\u7684 JavaScript \u529f\u80fd\u4ee5\u524d\u6240\u672a\u6709\u7684\u65b9\u5f0f\u63d0\u5347\u60a8\u7684\u4ee3\u7801\uff01\u63d2\u56fe\" \/><\/p>\n<h2> 1. \u9876\u7ea7\u7b49\u5f85 \u2013 \u5f02\u6b65\u7b80\u5316\uff01 <\/h2>\n<p>\u5f02\u6b65\u4ee3\u7801\u9700\u8981\u5c06\u6240\u6709\u5185\u5bb9\u5305\u88c5\u5728\u51fd\u6570\u4e2d\u7684\u65e5\u5b50\u5df2\u7ecf\u4e00\u53bb\u4e0d\u590d\u8fd4\u4e86\u3002\u901a\u8fc7\u9876\u7ea7\u7684awt\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u5728\u6a21\u5757\u4e2d\u4f7f\u7528await\uff0c\u800c\u4e0d\u9700\u8981\u5f02\u6b65\u51fd\u6570\u5305\u88c5\u5668\u3002\u6b64\u529f\u80fd\u5bf9\u4e8e\u7b80\u5316\u4ee3\u7801\u548c\u51cf\u5c11\u6837\u677f\u6587\u4ef6\u7279\u522b\u65b9\u4fbf<\/p>\n<p>\u5728\u9876\u7ea7\u7b49\u5f85\u4e4b\u524d\uff0c\u83b7\u53d6\u6570\u636e\u9700\u8981\u4e00\u4e2a\u5f02\u6b65\u51fd\u6570\uff1a<\/p>\n<pre>async function fetchdata() {\n  const response = await fetch('https:\/\/api.example.com\/data');\n  const data = await response.json();\n  return data;\n}\nfetchdata();\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u901a\u8fc7\u9876\u7ea7\u7684await\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6839\u7ea7\u522b\u8c03\u7528await\uff1a<\/p>\n<pre>const response = await fetch('https:\/\/api.example.com\/data');\nconst data = await response.json();\nconsole.log(data);\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4f7f\u5f97\u6a21\u5757\u4e2d\u7684\u5f02\u6b65\u4ee3\u7801\u66f4\u52a0\u7b80\u5355\u548c\u53ef\u8bfb\uff0c\u975e\u5e38\u9002\u5408\u5feb\u901f\u8bbe\u7f6e\u811a\u672c\u6216\u5728\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6\u52a0\u8f7d\u6570\u636e\u3002<\/p>\n<h2> 2. pipeline operator (|&gt;) \u2013 \u66f4\u6e05\u6670\u7684\u51fd\u6570\u94fe <\/h2>\n<p>\u7ba1\u9053\u8fd0\u7b97\u7b26\u5f15\u5165\u4e86\u4e00\u79cd\u4ee5\u53ef\u8bfb\u683c\u5f0f\u94fe\u63a5\u51fd\u6570\u7684\u65b0\u65b9\u6cd5\u3002\u8fd9\u5c31\u50cf\u901a\u8fc7\u4e00\u7cfb\u5217\u51fd\u6570\u5728\u89c6\u89c9\u4e0a\u201c\u7ba1\u9053\u201d\u6570\u636e\u4e00\u6837\uff0c\u4f7f\u4ee3\u7801\u81ea\u7136\u5730\u4ece\u5de6\u5230\u53f3\u6d41\u52a8\u3002<\/p>\n<p>\u8003\u8651\u5728\u4e0d\u4f7f\u7528\u7ba1\u9053\u8fd0\u7b97\u7b26\u7684\u60c5\u51b5\u4e0b\u901a\u8fc7\u591a\u4e2a\u51fd\u6570\u8f6c\u6362\u503c\uff1a<\/p>\n<pre>const result = capitalize(square(double(value)));\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528\u7ba1\u9053\u8fd0\u7b97\u7b26\uff0c\u8f6c\u6362\u66f4\u52a0\u6e05\u6670\uff1a<\/p>\n<pre>const result = value |&gt; double |&gt; square |&gt; capitalize;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e00\u53d8\u5316\u4e0d\u4ec5\u770b\u8d77\u6765\u66f4\u5e72\u51c0\uff0c\u800c\u4e14\u66f4\u7b80\u6d01\u3002\u5b83\u4e5f\u66f4\u5bb9\u6613\u9075\u5faa\u548c\u7ef4\u62a4\uff0c\u7279\u522b\u662f\u5bf9\u4e8e\u5177\u6709\u591a\u4e2a\u8f6c\u6362\u6b65\u9aa4\u7684\u51fd\u6570\u200b<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<h2> 3. promise.withresolvers \u2013 \u8ba9 promise \u53d8\u5f97\u7b80\u5355 <\/h2>\n<p>\u5904\u7406promise\u901a\u5e38\u9700\u8981\u521b\u5efa\u4e00\u4e2apromise\uff0c\u7136\u540e\u5206\u522b\u5b9a\u4e49resolve\u548creject\u51fd\u6570\u3002 promise.withresolvers \u901a\u8fc7\u5c06 promise \u4e0e\u89e3\u6790\u548c\u62d2\u7edd\u5904\u7406\u7a0b\u5e8f\u6346\u7ed1\u5728\u4e00\u8d77\u6765\u7b80\u5316\u8fd9\u4e00\u8fc7\u7a0b\uff0c\u4f7f\u5f02\u6b65\u5de5\u4f5c\u6d41\u7a0b\u66f4\u52a0\u6e05\u6670\u3002<\/p>\n<p>\u4e4b\u524d<\/p>\n<pre>let resolve, reject;\nconst promise = new promise((res, rej) =&gt; {\n  resolve = res;\n  reject = rej;\n});\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f7f\u7528 promise.withresolvers\uff1a<\/p>\n<pre>const { promise, resolve, reject } = promise.withresolvers();\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2> 4. \u8bb0\u5f55\u548c\u5143\u7ec4\u2014\u2014\u4e0d\u53ef\u53d8\u7684\u6570\u636e\u7ed3\u6784 <\/h2>\n<p>\u8bb0\u5f55\u548c\u5143\u7ec4\u76f4\u63a5\u4e3a javascript \u5e26\u6765\u4e86\u4e0d\u53d8\u6027\uff0c\u8ba9\u60a8\u53ef\u4ee5\u521b\u5efa\u521b\u5efa\u540e\u65e0\u6cd5\u66f4\u6539\u7684\u6570\u636e\u7ed3\u6784\u3002\u8bb0\u5f55\u5c31\u50cf\u4e0d\u53ef\u53d8\u5bf9\u8c61\u4e00\u6837\u5de5\u4f5c\uff0c\u800c\u5143\u7ec4\u5219\u50cf\u56fa\u5b9a\u957f\u5ea6\u3001\u4e0d\u53ef\u53d8\u6570\u7ec4\u4e00\u6837\u5de5\u4f5c\u3002\u5b83\u4eec\u4f7f\u6570\u636e\u5b8c\u6574\u6027\u66f4\u5bb9\u6613\u7ef4\u62a4\uff0c\u51cf\u5c11\u610f\u5916\u66f4\u6539<\/p>\n<p>\u521b\u5efa\u8bb0\u5f55\u548c\u5143\u7ec4\uff1a<\/p>\n<pre>const person = #{ name: 'alice', age: 30 };  \/\/ record\nconst colors = #['red', 'green', 'blue'];    \/\/ tuple\n\n\/\/ any attempt to modify throws an error\nperson.name = 'bob'; \/\/ error\ncolors.push('yellow'); \/\/ error\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u79cd\u4e0d\u53d8\u6027\u4f7f\u5f97\u8bb0\u5f55\u548c\u5143\u7ec4\u975e\u5e38\u9002\u5408\u8868\u793a\u56fa\u5b9a\u6570\u636e\uff0c\u4f8b\u5982\u914d\u7f6e\u6216\u5e38\u91cf<\/p>\n<h2> 5. string.towellformed \u548c string.iswellformed \u2013 \u66f4\u597d\u7684 unicode \u5904\u7406 <\/h2>\n<p>unicode \u9519\u8bef\u53ef\u80fd\u4f1a\u610f\u5916\u51fa\u73b0\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u56fd\u9645\u6587\u672c\u65f6\u3002 string.towellformed \u548c string.iswellformed \u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u68c0\u67e5\u548c\u8f6c\u6362\u5b57\u7b26\u4e32\u7684 unicode \u6b63\u786e\u6027\u3002\u5b83\u4eec\u6709\u52a9\u4e8e\u907f\u514d\u591a\u8bed\u8a00\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u6e32\u67d3\u95ee\u9898\u548c\u6570\u636e\u635f\u574f<\/p>\n<pre>const text = 'Hello, uD800'; \/\/ Lone surrogate\nconsole.log(text.isWellFormed()); \/\/ false\n\nconst wellFormedText = text.toWellFormed();\nconsole.log(wellFormedText); \/\/ Corrected Unicode text\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e9b\u65b9\u6cd5\u5bf9\u4e8e\u9700\u8981\u5f3a\u5927\u7684\u5168\u5c40\u6587\u672c\u5904\u7406\u7684\u5e94\u7528\u7a0b\u5e8f\u81f3\u5173\u91cd\u8981\uff0c\u786e\u4fdd\u5b57\u7b26\u4e32\u5bf9\u4e8e unicode \u8868\u793a\u6709\u6548\u4e14\u683c\u5f0f\u826f\u597d<\/p>\n<h2> \u7ed3\u8bba\uff1a\u73b0\u4ee3 javascript\uff0c\u73b0\u5728\u53d8\u5f97\u66f4\u597d <\/h2>\n<p>ecmascript 2024 \u5305\u542b\u591a\u79cd\u5de5\u5177\uff0c\u53ef\u4e3a javascript \u7f16\u7801\u5e26\u6765\u8f7b\u677e\u3001\u6e05\u6670\u548c\u53ef\u9760\u7684\u6548\u679c\u3002\u4ece\u5f02\u6b65\u7b80\u5316\u5230\u4e0d\u53d8\u6027\u548c\u66f4\u597d\u7684 unicode \u5904\u7406\uff0c\u8fd9\u4e9b\u66f4\u65b0\u786e\u4fdd javascript \u7ee7\u7eed\u6ee1\u8db3\u73b0\u4ee3\u5f00\u53d1\u7684\u9700\u6c42\u3002\u56e0\u6b64\uff0c\u6df1\u5165\u7814\u7a76\u3001\u5c1d\u8bd5\u8fd9\u4e9b\u529f\u80fd\uff0c\u770b\u770b\u5b83\u4eec\u5982\u4f55\u6539\u53d8\u60a8\u7684\u7f16\u7801\u4f53\u9a8c\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fECMAScript \u4e2d\u6539\u53d8\u4e16\u754c\u7684 JavaScript \u529f\u80fd\u4ee5\u524d\u6240\u672a\u6709\u7684\u65b9\u5f0f\u63d0\u5347\u60a8\u7684\u4ee3\u7801\uff01\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u9876\u7ea7\u7b49\u5f85 \u2013 \u5f02\u6b65\u7b80\u5316\uff01 \u5f02\u6b65\u4ee3\u7801\u9700\u8981\u5c06\u6240\u6709\u5185\u5bb9\u5305\u88c5\u5728\u51fd\u6570\u4e2d\u7684\u65e5\u5b50\u5df2\u7ecf\u4e00\u53bb\u4e0d\u590d\u8fd4\u4e86\u3002\u901a\u8fc7\u9876\u7ea7\u7684awt\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u5728\u6a21\u5757\u4e2d\u4f7f\u7528await\uff0c\u800c\u4e0d\u9700\u8981\u5f02\u6b65\u51fd\u6570\u5305\u88c5\u5668\u3002\u6b64\u529f\u80fd\u5bf9\u4e8e\u7b80\u5316\u4ee3\u7801\u548c\u51cf\u5c11\u6837\u677f\u6587\u4ef6\u7279\u522b\u65b9\u4fbf \u5728\u9876\u7ea7\u7b49\u5f85\u4e4b\u524d\uff0c\u83b7\u53d6\u6570\u636e\u9700\u8981\u4e00\u4e2a\u5f02\u6b65\u51fd\u6570\uff1a async function fetchdata() { const response = await fetch(&#8216;https:\/\/api.example.com\/data&#8217;); const data = await response.json(); return data; } fetchdata(); \u767b\u5f55\u540e\u590d\u5236 \u73b0\u5728\uff0c\u901a\u8fc7\u9876\u7ea7\u7684await\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6839\u7ea7\u522b\u8c03\u7528await\uff1a const response = await fetch(&#8216;https:\/\/api.example.com\/data&#8217;); const data = await response.json(); console.log(data); \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u4f7f\u5f97\u6a21\u5757\u4e2d\u7684\u5f02\u6b65\u4ee3\u7801\u66f4\u52a0\u7b80\u5355\u548c\u53ef\u8bfb\uff0c\u975e\u5e38\u9002\u5408\u5feb\u901f\u8bbe\u7f6e\u811a\u672c\u6216\u5728\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6\u52a0\u8f7d\u6570\u636e\u3002 2. pipeline operator (|&gt;) \u2013 \u66f4\u6e05\u6670\u7684\u51fd\u6570\u94fe \u7ba1\u9053\u8fd0\u7b97\u7b26\u5f15\u5165\u4e86\u4e00\u79cd\u4ee5\u53ef\u8bfb\u683c\u5f0f\u94fe\u63a5\u51fd\u6570\u7684\u65b0\u65b9\u6cd5\u3002\u8fd9\u5c31\u50cf\u901a\u8fc7\u4e00\u7cfb\u5217\u51fd\u6570\u5728\u89c6\u89c9\u4e0a\u201c\u7ba1\u9053\u201d\u6570\u636e\u4e00\u6837\uff0c\u4f7f\u4ee3\u7801\u81ea\u7136\u5730\u4ece\u5de6\u5230\u53f3\u6d41\u52a8\u3002 \u8003\u8651\u5728\u4e0d\u4f7f\u7528\u7ba1\u9053\u8fd0\u7b97\u7b26\u7684\u60c5\u51b5\u4e0b\u901a\u8fc7\u591a\u4e2a\u51fd\u6570\u8f6c\u6362\u503c\uff1a const result = capitalize(square(double(value))); \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u7ba1\u9053\u8fd0\u7b97\u7b26\uff0c\u8f6c\u6362\u66f4\u52a0\u6e05\u6670\uff1a const result [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-2439","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=2439"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2439\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}