{"id":29382,"date":"2024-11-25T11:10:22","date_gmt":"2024-11-25T03:10:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/29382\/"},"modified":"2024-11-25T11:10:22","modified_gmt":"2024-11-25T03:10:22","slug":"es6%e6%96%b0%e7%89%b9%e6%80%a7%e5%bc%80%e5%8f%91%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%ef%bc%889%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/29382\/","title":{"rendered":"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09"},"content":{"rendered":"<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u4e0d\u9700\u8981\u7533\u660e\u4e25\u683c\u6a21\u5f0f<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u4e0d\u9700\u8981\u5c06&#8221;use strict&#8221;\u653e\u5728\u811a\u672c\u6587\u4ef6\u7684\u7b2c\u4e00\u884c\uff0c\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u5de5\u5177\u5f00\u542fES6\u8f6c\u6362\u529f\u80fd\u7684\u60c5\u51b5\u4e0b\uff0c\u9ed8\u8ba4\u542f\u7528javasctipt\u4e25\u683c\u6a21\u5f0f(Strict Mode)\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u7528\u5757\u7ea7\u4f5c\u7528\u57df\u4ee3\u66ffIIFES<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">IIFE(\u7acb\u5373\u6267\u884c\u51fd\u6570\u8868\u8fbe\u5f0f)\u7684\u901a\u5e38\u7528\u9014\u662f\u521b\u9020\u4e00\u4e2a\u5185\u90e8\u7684\u4f5c\u7528\u57df\uff0c\u5728ES6\u4e2d\uff0c\u80fd\u591f\u521b\u9020\u4e00\u4e2a\u5757\u7ea7\u4f5c\u7528\u57df\u800c\u4e0d\u4ec5\u9650\u4e8e\u51fd\u6570\u4f5c\u7528\u57df\u3002\u5757\u7ea7\u4f5c\u7528\u57df\u7684\u51fa\u73b0\u4f7f\u5f97\u83b7\u5f97\u5e7f\u6cdb\u5e94\u7528\u7684\u7acb\u5373\u6267\u884c\u533f\u540d\u51fd\u6570(IIFE)\u4e0d\u518d\u5fc5\u8981\u4e86\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">IIFE\uff1a<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/3754ed4e3a2a7eaccf848f7797254ef3-0.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">ES6\u5757\u7ea7\u4f5c\u7528\u57df\uff1a<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/3754ed4e3a2a7eaccf848f7797254ef3-1.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe1\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe1\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u4f7f\u7528for&#8230;of\u5faa\u73af<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">ES6 \u501f\u9274 C++\u3001Java\u3001C# \u548c Python \u8bed\u8a00\uff0c\u5f15\u5165\u4e86for&#8230;of\u5faa\u73af\uff0c\u4f5c\u4e3a\u904d\u5386\u6240\u6709\u6570\u636e\u7ed3\u6784\u7684\u7edf\u4e00\u7684\u65b9\u6cd5\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u53ea\u8981\u90e8\u7f72\u4e86Symbol.iterator\u5c5e\u6027\uff0c\u5c31\u88ab\u89c6\u4e3a\u5177\u6709iterator\u63a5\u53e3\uff0c\u5c31\u53ef\u4ee5\u7528for&#8230;of\u5faa\u73af\u904d\u5386\u5b83\u7684\u6210\u5458\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cfor&#8230;of\u5faa\u73af\u5185\u90e8\u8c03\u7528\u7684\u662f\u6570\u636e\u7ed3\u6784\u7684Symbol.iterator\u65b9\u6cd5\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">for&#8230;of\u5faa\u73af\u53ef\u4ee5\u4f7f\u7528\u7684\u8303\u56f4\u5305\u62ec\u6570\u7ec4\u3001Set \u548c Map \u7ed3\u6784\u3001\u67d0\u4e9b\u7c7b\u4f3c\u6570\u7ec4\u7684\u5bf9\u8c61\u3001Generator \u5bf9\u8c61\u4ee5\u53ca\u5b57\u7b26\u4e32\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u904d\u5386\u6570\u7ec4\uff1a<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/3754ed4e3a2a7eaccf848f7797254ef3-2.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe2\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe2\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u904d\u5386Set\uff1a<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/3754ed4e3a2a7eaccf848f7797254ef3-3.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe3\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe3\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">for&#8230;of \u7528\u4e8e\u904d\u5386\u4e00\u4e2a\u8fed\u4ee3\u5668\uff1a<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/3754ed4e3a2a7eaccf848f7797254ef3-4.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe4\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe4\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">for&#8230;in \u7528\u6765\u904d\u5386\u5bf9\u8c61\u4e2d\u7684\u5c5e\u6027\uff1a<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/3754ed4e3a2a7eaccf848f7797254ef3-5.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe5\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe5\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u6570\u7ec4\u5b9e\u4f8b\u7684forEach\u65b9\u6cd5\u904d\u5386\u4e00\u4e2a\u6570\u7ec4\u7684\u5143\u7d20\u548c\u7d22\u5f15<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/3754ed4e3a2a7eaccf848f7797254ef3-6.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe6\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe6\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">for&#8230;of\u5faa\u73af\u652f\u6301 ES6 \u8fed\u4ee3(\u901a\u8fc7 iterables \u548c iterators)\u548c\u89e3\u6784\u3002\u3002\u901a\u8fc7\u6570\u7ec4\u7684ES6\u65b0\u65b9\u6cd5enteries()\u7ed3\u5408\u89e3\u6784\uff0c\u53ef\u4ee5\u4ee3\u66ff\u6570\u7ec4\u5b9e\u4f8b\u7684forEach\u65b9\u6cd5\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/8b7589124c07c68dcfa3ce378a33044b-7.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe7\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe7\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u901a\u8fc7\u53d8\u91cf\u89e3\u6784\u4ea4\u6362\u4e24\u4e2a\u53d8\u91cf\u7684\u503c<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5982\u679c\u5c06\u4e00\u5bf9\u53d8\u91cf\u653e\u5165\u4e00\u4e2a\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u6570\u7ec4\u89e3\u6784\u8d4b\u503c\u76f8\u540c\u7684\u53d8\u91cf(\u987a\u5e8f\u4e0d\u540c)\uff0c\u5c31\u53ef\u4ee5\u4e0d\u4f9d\u8d56\u4e2d\u95f4\u53d8\u91cf\u4ea4\u6362\u4e24\u4e2a\u53d8\u91cf\u7684\u503c\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/8b7589124c07c68dcfa3ce378a33044b-8.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe8\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe8\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u4f7f\u7528\u5c55\u5f00\u8fd0\u7b97\u7b26\u548c\u5269\u4f59\u64cd\u4f5c\u7b26<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5c55\u5f00\u8fd0\u7b97\u7b26(the spread syntax )\u5141\u8bb8\u4e00\u4e2a\u8868\u8fbe\u5f0f\u5728\u67d0\u5904\u5c55\u5f00\uff0c\u5728\u591a\u4e2a\u53c2\u6570(\u7528\u4e8e\u51fd\u6570\u8c03\u7528)\u6216\u8005\u591a\u4e2a\u5143\u7d20(\u7528\u4e8e\u6570\u7ec4\u5b57\u9762\u91cf)\u6216\u8005\u591a\u4e2a\u53d8\u91cf(\u7528\u4e8e\u89e3\u6784\u8d4b\u503c)\u7684\u5730\u65b9\u5c31\u4f1a\u8fd9\u6837\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u7528\u4e8e\u51fd\u6570\u8c03\u7528\u8bed\u6cd5\uff1a<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/8b7589124c07c68dcfa3ce378a33044b-9.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe9\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe9\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u7528\u4e8e\u6570\u7ec4\u5b57\u9762\u91cf\u8bed\u6cd5:<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/8b7589124c07c68dcfa3ce378a33044b-10.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe10\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe10\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5269\u4f59\u64cd\u4f5c\u7b26(the rest operator)\uff0c\u5b83\u7684\u6837\u5b50\u770b\u8d77\u6765\u548c\u5c55\u5f00\u64cd\u4f5c\u7b26\u4e00\u6837\uff0c\u4f46\u662f\u5b83\u662f\u7528\u4e8e\u89e3\u6784\u6570\u7ec4\u548c\u5bf9\u8c61\u3002\u5728\u67d0\u79cd\u7a0b\u5ea6\u4e0a\uff0c\u5269\u4f59\u5143\u7d20\u548c\u5c55\u5f00\u5143\u7d20\u76f8\u53cd\uff0c\u5c55\u5f00\u5143\u7d20\u4f1a\u201c\u5c55\u5f00\u201d\u6570\u7ec4\u53d8\u6210\u591a\u4e2a\u5143\u7d20\uff0c\u5269\u4f59\u5143\u7d20\u4f1a\u6536\u96c6\u591a\u4e2a\u5143\u7d20\u548c\u201c\u538b\u7f29\u201d\u6210\u4e00\u4e2a\u5355\u4e00\u7684\u5143\u7d20\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5269\u4f59\u53c2\u6570(rest parameter)\u5141\u8bb8\u957f\u5ea6\u4e0d\u786e\u5b9a\u7684\u5b9e\u53c2\u8868\u793a\u4e3a\u4e00\u4e2a\u6570\u7ec4\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5269\u4f59\u53c2\u6570\u8bed\u6cd5\uff1a<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/8b7589124c07c68dcfa3ce378a33044b-11.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe11\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe11\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u4f7f\u7528\u793a\u4f8b\uff1a<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/8b7589124c07c68dcfa3ce378a33044b-12.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe12\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe12\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u6bd4\u8f83\u4e24\u4e2a\u503c\u662f\u5426\u4e25\u683c\u76f8\u7b49<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">Object.is()\u7528\u6765\u6bd4\u8f83\u4e24\u4e2a\u503c\u662f\u5426\u4e25\u683c\u76f8\u7b49\u3002\u5b83\u4e0e\u4e25\u683c\u6bd4\u8f83\u8fd0\u7b97\u7b26(===)\u7684\u884c\u4e3a\u57fa\u672c\u4e00\u81f4\uff0c\u4e0d\u540c\u4e4b\u5904\u53ea\u6709\u4e24\u4e2a\uff1a\u4e00\u662f+0\u4e0d\u7b49\u4e8e-0\uff0c\u4e8c\u662fNaN\u7b49\u4e8e\u81ea\u8eab\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/ac858c046562abde16e91b5b2c8a1782-13.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe13\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe13\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u4e3a\u4e86\u6ee1\u8db3\u79fb\u52a8\u7aef\u7684\u9002\u914d\uff0c\u53ef\u5728\u7a0b\u5e8f\u4e2d\u52a0\u5165Polyfill<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/ac858c046562abde16e91b5b2c8a1782-14.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe14\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe14\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5bf9\u8c61\u5c5e\u6027\u590d\u5236<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">Object.assign\u65b9\u6cd5\u7528\u6765\u5c06\u6e90\u5bf9\u8c61(source)\u7684\u6240\u6709\u53ef\u679a\u4e3e\u5c5e\u6027\uff0c\u590d\u5236\u5230\u76ee\u6807\u5bf9\u8c61(target)\u3002\u5b83\u81f3\u5c11\u9700\u8981\u4e24\u4e2a\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u76ee\u6807\u5bf9\u8c61\uff0c\u540e\u9762\u7684\u53c2\u6570\u90fd\u662f\u6e90\u5bf9\u8c61\u3002\u53ea\u8981\u6709\u4e00\u4e2a\u53c2\u6570\u4e0d\u662f\u5bf9\u8c61\uff0c\u5c31\u4f1a\u629b\u51faTypeError\u9519\u8bef\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/ac858c046562abde16e91b5b2c8a1782-15.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe15\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe15\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5982\u679c\u76ee\u6807\u5bf9\u8c61\u4e0e\u6e90\u5bf9\u8c61\u6709\u540c\u540d\u5c5e\u6027\uff0c\u6216\u591a\u4e2a\u6e90\u5bf9\u8c61\u6709\u540c\u540d\u5c5e\u6027\uff0c\u5219\u540e\u9762\u7684\u5c5e\u6027\u4f1a\u8986\u76d6\u524d\u9762\u7684\u5c5e\u6027\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u4e3a\u4e86\u6ee1\u8db3\u79fb\u52a8\u7aef\u7684\u9002\u914d\uff0c\u53ef\u5728\u7a0b\u5e8f\u4e2d\u52a0\u5165Polyfill<\/span><\/p>\n<p style=\"line-height: 2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/ac858c046562abde16e91b5b2c8a1782-16.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe16\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff089\uff09\u63d2\u56fe16\" \/><br \/><\/span><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fES6\u65b0\u7279\u6027\u5f00\u53d1\u5c0f\u7a0b\u5e8f\uff089\uff09\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>\u4e0d\u9700\u8981\u7533\u660e\u4e25\u683c\u6a21\u5f0f \u4e0d\u9700\u8981\u5c06&#8221;use strict&#8221;\u653e\u5728\u811a\u672c\u6587\u4ef6\u7684\u7b2c\u4e00\u884c\uff0c\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u5de5\u5177\u5f00\u542fES6\u8f6c\u6362\u529f\u80fd\u7684\u60c5\u51b5\u4e0b\uff0c\u9ed8\u8ba4\u542f\u7528javasctipt\u4e25\u683c\u6a21\u5f0f(Strict Mode)\u3002 \u7528\u5757\u7ea7\u4f5c\u7528\u57df\u4ee3\u66ffIIFES IIFE(\u7acb\u5373\u6267\u884c\u51fd\u6570\u8868\u8fbe\u5f0f)\u7684\u901a\u5e38\u7528\u9014\u662f\u521b\u9020\u4e00\u4e2a\u5185\u90e8\u7684\u4f5c\u7528\u57df\uff0c\u5728ES6\u4e2d\uff0c\u80fd\u591f\u521b\u9020\u4e00\u4e2a\u5757\u7ea7\u4f5c\u7528\u57df\u800c\u4e0d\u4ec5\u9650\u4e8e\u51fd\u6570\u4f5c\u7528\u57df\u3002\u5757\u7ea7\u4f5c\u7528\u57df\u7684\u51fa\u73b0\u4f7f\u5f97\u83b7\u5f97\u5e7f\u6cdb\u5e94\u7528\u7684\u7acb\u5373\u6267\u884c\u533f\u540d\u51fd\u6570(IIFE)\u4e0d\u518d\u5fc5\u8981\u4e86\u3002 IIFE\uff1a ES6\u5757\u7ea7\u4f5c\u7528\u57df\uff1a \u4f7f\u7528for&#8230;of\u5faa\u73af ES6 \u501f\u9274 C++\u3001Java\u3001C# \u548c Python \u8bed\u8a00\uff0c\u5f15\u5165\u4e86for&#8230;of\u5faa\u73af\uff0c\u4f5c\u4e3a\u904d\u5386\u6240\u6709\u6570\u636e\u7ed3\u6784\u7684\u7edf\u4e00\u7684\u65b9\u6cd5\u3002 \u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u53ea\u8981\u90e8\u7f72\u4e86Symbol.iterator\u5c5e\u6027\uff0c\u5c31\u88ab\u89c6\u4e3a\u5177\u6709iterator\u63a5\u53e3\uff0c\u5c31\u53ef\u4ee5\u7528for&#8230;of\u5faa\u73af\u904d\u5386\u5b83\u7684\u6210\u5458\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cfor&#8230;of\u5faa\u73af\u5185\u90e8\u8c03\u7528\u7684\u662f\u6570\u636e\u7ed3\u6784\u7684Symbol.iterator\u65b9\u6cd5\u3002 for&#8230;of\u5faa\u73af\u53ef\u4ee5\u4f7f\u7528\u7684\u8303\u56f4\u5305\u62ec\u6570\u7ec4\u3001Set \u548c Map \u7ed3\u6784\u3001\u67d0\u4e9b\u7c7b\u4f3c\u6570\u7ec4\u7684\u5bf9\u8c61\u3001Generator \u5bf9\u8c61\u4ee5\u53ca\u5b57\u7b26\u4e32\u3002 \u904d\u5386\u6570\u7ec4\uff1a \u904d\u5386Set\uff1a for&#8230;of \u7528\u4e8e\u904d\u5386\u4e00\u4e2a\u8fed\u4ee3\u5668\uff1a for&#8230;in \u7528\u6765\u904d\u5386\u5bf9\u8c61\u4e2d\u7684\u5c5e\u6027\uff1a \u6570\u7ec4\u5b9e\u4f8b\u7684forEach\u65b9\u6cd5\u904d\u5386\u4e00\u4e2a\u6570\u7ec4\u7684\u5143\u7d20\u548c\u7d22\u5f15 for&#8230;of\u5faa\u73af\u652f\u6301 ES6 \u8fed\u4ee3(\u901a\u8fc7 iterables \u548c iterators)\u548c\u89e3\u6784\u3002\u3002\u901a\u8fc7\u6570\u7ec4\u7684ES6\u65b0\u65b9\u6cd5enteries()\u7ed3\u5408\u89e3\u6784\uff0c\u53ef\u4ee5\u4ee3\u66ff\u6570\u7ec4\u5b9e\u4f8b\u7684forEach\u65b9\u6cd5\u3002 \u901a\u8fc7\u53d8\u91cf\u89e3\u6784\u4ea4\u6362\u4e24\u4e2a\u53d8\u91cf\u7684\u503c \u5982\u679c\u5c06\u4e00\u5bf9\u53d8\u91cf\u653e\u5165\u4e00\u4e2a\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u6570\u7ec4\u89e3\u6784\u8d4b\u503c\u76f8\u540c\u7684\u53d8\u91cf(\u987a\u5e8f\u4e0d\u540c)\uff0c\u5c31\u53ef\u4ee5\u4e0d\u4f9d\u8d56\u4e2d\u95f4\u53d8\u91cf\u4ea4\u6362\u4e24\u4e2a\u53d8\u91cf\u7684\u503c\u3002 \u4f7f\u7528\u5c55\u5f00\u8fd0\u7b97\u7b26\u548c\u5269\u4f59\u64cd\u4f5c\u7b26 \u5c55\u5f00\u8fd0\u7b97\u7b26(the spread syntax )\u5141\u8bb8\u4e00\u4e2a\u8868\u8fbe\u5f0f\u5728\u67d0\u5904\u5c55\u5f00\uff0c\u5728\u591a\u4e2a\u53c2\u6570(\u7528\u4e8e\u51fd\u6570\u8c03\u7528)\u6216\u8005\u591a\u4e2a\u5143\u7d20(\u7528\u4e8e\u6570\u7ec4\u5b57\u9762\u91cf)\u6216\u8005\u591a\u4e2a\u53d8\u91cf(\u7528\u4e8e\u89e3\u6784\u8d4b\u503c)\u7684\u5730\u65b9\u5c31\u4f1a\u8fd9\u6837\u3002 \u7528\u4e8e\u51fd\u6570\u8c03\u7528\u8bed\u6cd5\uff1a \u7528\u4e8e\u6570\u7ec4\u5b57\u9762\u91cf\u8bed\u6cd5: \u5269\u4f59\u64cd\u4f5c\u7b26(the rest operator)\uff0c\u5b83\u7684\u6837\u5b50\u770b\u8d77\u6765\u548c\u5c55\u5f00\u64cd\u4f5c\u7b26\u4e00\u6837\uff0c\u4f46\u662f\u5b83\u662f\u7528\u4e8e\u89e3\u6784\u6570\u7ec4\u548c\u5bf9\u8c61\u3002\u5728\u67d0\u79cd\u7a0b\u5ea6\u4e0a\uff0c\u5269\u4f59\u5143\u7d20\u548c\u5c55\u5f00\u5143\u7d20\u76f8\u53cd\uff0c\u5c55\u5f00\u5143\u7d20\u4f1a\u201c\u5c55\u5f00\u201d\u6570\u7ec4\u53d8\u6210\u591a\u4e2a\u5143\u7d20\uff0c\u5269\u4f59\u5143\u7d20\u4f1a\u6536\u96c6\u591a\u4e2a\u5143\u7d20\u548c\u201c\u538b\u7f29\u201d\u6210\u4e00\u4e2a\u5355\u4e00\u7684\u5143\u7d20\u3002 \u5269\u4f59\u53c2\u6570(rest parameter)\u5141\u8bb8\u957f\u5ea6\u4e0d\u786e\u5b9a\u7684\u5b9e\u53c2\u8868\u793a\u4e3a\u4e00\u4e2a\u6570\u7ec4\u3002 \u5269\u4f59\u53c2\u6570\u8bed\u6cd5\uff1a \u4f7f\u7528\u793a\u4f8b\uff1a \u6bd4\u8f83\u4e24\u4e2a\u503c\u662f\u5426\u4e25\u683c\u76f8\u7b49 Object.is()\u7528\u6765\u6bd4\u8f83\u4e24\u4e2a\u503c\u662f\u5426\u4e25\u683c\u76f8\u7b49\u3002\u5b83\u4e0e\u4e25\u683c\u6bd4\u8f83\u8fd0\u7b97\u7b26(===)\u7684\u884c\u4e3a\u57fa\u672c\u4e00\u81f4\uff0c\u4e0d\u540c\u4e4b\u5904\u53ea\u6709\u4e24\u4e2a\uff1a\u4e00\u662f+0\u4e0d\u7b49\u4e8e-0\uff0c\u4e8c\u662fNaN\u7b49\u4e8e\u81ea\u8eab\u3002 \u4e3a\u4e86\u6ee1\u8db3\u79fb\u52a8\u7aef\u7684\u9002\u914d\uff0c\u53ef\u5728\u7a0b\u5e8f\u4e2d\u52a0\u5165Polyfill \u5bf9\u8c61\u5c5e\u6027\u590d\u5236 Object.assign\u65b9\u6cd5\u7528\u6765\u5c06\u6e90\u5bf9\u8c61(source)\u7684\u6240\u6709\u53ef\u679a\u4e3e\u5c5e\u6027\uff0c\u590d\u5236\u5230\u76ee\u6807\u5bf9\u8c61(target)\u3002\u5b83\u81f3\u5c11\u9700\u8981\u4e24\u4e2a\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u76ee\u6807\u5bf9\u8c61\uff0c\u540e\u9762\u7684\u53c2\u6570\u90fd\u662f\u6e90\u5bf9\u8c61\u3002\u53ea\u8981\u6709\u4e00\u4e2a\u53c2\u6570\u4e0d\u662f\u5bf9\u8c61\uff0c\u5c31\u4f1a\u629b\u51faTypeError\u9519\u8bef\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-29382","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29382","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=29382"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29382\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=29382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=29382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=29382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}