{"id":7908,"date":"2018-08-06T23:57:58","date_gmt":"2018-08-06T15:57:58","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=7908"},"modified":"2018-10-25T14:54:31","modified_gmt":"2018-10-25T06:54:31","slug":"for-in-es6-for-of","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2018\/08\/for-in-es6-for-of\/","title":{"rendered":"\u770b\uff0cfor..in\u548cfor..of\u5728\u90a3\u91cc\u5435\u67b6\uff01"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=7908\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=7908<\/a><br \/>\n\u672c\u6587\u53ef\u5168\u6587\u8f6c\u8f7d\uff0c\u4f46\u9700\u5f97\u5230\u539f\u4f5c\u8005\u4e66\u9762\u8bb8\u53ef\uff0c\u540c\u65f6\u4fdd\u7559\u539f\u4f5c\u8005\u548c\u51fa\u5904\uff0c\u6458\u8981\u5f15\u6d41\u5219\u968f\u610f\u3002<\/p>\n<p><span class=\"s\">\u672c\u6545\u4e8b\u7eaf\u5c5e\u865a\u6784\uff0c\u5982\u6709\u96f7\u540c\uff0c\u606d\u559c\u4f60\uff0c\u4eba\u54c1\u4e0d\u9519\u3002\u672c\u65876000\u591a\u5b57\uff0c\u9605\u8bfb\u7ea615\u5206\u949f\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201808\/for-in-of-thumb.jpg\" width=\"161\" height=\"100\" alt=\"\u6587\u7ae0\u7f29\u7565\u56fe\" class=\"alignright thumb size-medium\" style=\"position:absolute;clip:rect(0 0 0 \n 0);\" \/> <\/p>\n<p>\u4eca\u5929\u53ef\u662f\u4e2a\u597d\u65e5\u5b50\uff01<\/p>\n<p>\u4f60\u95ee\u6211\u4e3a\u4ec0\u4e48\uff1f<\/p>\n<p>\u4f60\u8fd9\u90fd\u4e0d\u77e5\u9053\uff0cChinaJoy\u554a\uff01\u53ef\u662f\u8eab\u4e3a\u7626\u5b85\u7684\u6211\u7684\u5927\u65e5\u5b50\u554a\uff0c\u4e0d\u8bf4\u4e86\uff0c\u6211\u8d76\u65f6\u95f4\uff0c\u6211\u53ef\u662f\u5077\u5077\u7792\u7740\u6211\u8001\u5a46\u51fa\u6765\u7684\uff0c\u53ea\u80fd\u51fa\u67652\u5c0f\u65f6\u3002<\/p>\n<p>\u54c7\u585e\uff0c\u597d\u70ed\u95f9\u554a\uff01\u7433\u7405\u6ee1\u76ee\u7684\u5c55\u4f4d\uff0c\u7199\u7199\u6518\u6518\u7684\u4eba\u7fa4\uff0c\u5594\u54e6\u54e6\uff0c\u4e00\u6392\u6392\u7684showgirl\u90fd\u957f\u5f97\u90fd\u597d\u597d\u770b\uff0c\u867d\u7136\u548c\u6211\u8001\u5a46\u6bd4\u8fd8\u5dee\u70b9\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201808\/cj-mp.jpg\" width=\"180\" height=\"112\" alt=\"ChinaJoy 2018 showgirl\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u7a81\u7136\uff0c\u65c1\u8fb9\u4e00\u4e2a\u6234\u773c\u955c\u7684\u5c0f\u80d6\u5b50\u4e00\u58f0\u5927\u53eb\uff1a\u201c\u770b\uff0cfor..in\u548cfor..of\u5728\u90a3\u91cc\u5435\u67b6\uff01\u201d<\/p>\n<p>\u6211\u987a\u7740\u671b\u53bb\uff0c\u53ea\u89c12\u70b9\u949f\u65b9\u5411\u6709\u4e00\u7fa4\u7a7f\u7740\u683c\u5b50\u886b\u80cc\u7740\u7535\u8111\u5305\u7684\u4eba\u5728\u56f4\u89c2\u4ec0\u4e48\uff0c\u76f4\u89c9\u544a\u8bc9\u6211\uff0c\u6b64\u4e8b\u4e0d\u7b80\u5355\uff0c\u4e8e\u662f\u5c31\u8d70\u8fc7\u53bb\u4e00\u770b\u7a76\u7adf\u3002<\/p>\n<p>\u4e00\u6253\u542c\uff0c\u539f\u6765\u662f\u4e24\u4e2a\u4eba\u5728\u4e89\u8bba\u8c01\u7ed9\u201c\u5929\u4e0a\u5730\u4e0b\uff0c\u552f\u6211\u72ec\u840c\u201d\u7684\u8840\u5c0f\u677f\u62cd\u7167\u6548\u679c\u597d\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201808\/xxb.jpg\" width=\"163\" height=\"150\" alt=\"\u840c\u840c\u54d2\u8840\u5c0f\u677f\" class=\"alignnone size-medium\" \/> <img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201808\/2018-08-05_230115.jpg\" width=\"178\" height=\"150\" alt=\"\u840c\u840c\u54d2\u8840\u5c0f\u677f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4e0d\u8fc7\u8fd9\u4e24\u4eba\u957f\u5f97\u597d\u50cf\u554a\uff0c\u662f\u4eb2\u5144\u5f1f\u5427\uff0c\u4e00\u65f6\u95f4\u5206\u4e0d\u6e05\u8c01\u662f\u8c01\uff0c\u7b49\u4e0b\uff0c\u4e24\u4eba\u5934\u4e0a\u5e3d\u5b50\u4e0a\u7684\u6587\u5b57\u597d\u50cf\u4e0d\u4e00\u6837\uff0c\u4e00\u4e2a\u662f\u201c\u6deb\u201d\uff0c\u4e00\u4e2a\u662f\u201c\u6c61\u201d\u3002\u6211\u6478\u4e86\u6478\u6211\u6027\u611f\u7684\u4e0b\u5df4\u6c89\u601d\u4e86\u4e0b\uff0c\u54e6\uff0c\u7acb\u9a6c\u8c41\u7136\u5f00\u6717\u3002\u201c\u6deb\u201d\u6307\u7684\u662f<code>for..in<\/code>\uff0c<code>in<\/code>\u8bfb\u97f3\u548c\u201c\u6deb\u201d\u8fd1\u4f3c\uff1b\u201c\u6c61\u201d\u6307\u7684\u662f<code>for..of<\/code>\uff0c<code>of<\/code>\u8bfb\u97f3\u548c\u201c\u6c61\u201d\u8fd1\u4f3c\u3002\u54c8\u54c8\u54c8\uff0c\u6211\u53ef\u771f\u662f\u4e2a\u201c\u6deb\u624d\u201d\uff0c\u4e0d\u8fc7\u542c\u8d77\u6765\u597d\u50cf\u4e0d\u592a\u548c\u8c10\uff0c\u6211\u8fd8\u662f\u7528IN\u548cOF\u4ee3\u66ff\u4ed6\u4eec\u5427\u3002<\/p>\n<p>IN\u8bf4\uff1a\u201c\u6211\u7b2c\u4e00\u5c4aChinaJoy\u5c31\u8fc7\u6765\u62cd\u7167\u4e86\uff0c\u6574\u4e2a\u5708\u5b50\u8c01\u4e0d\u8ba4\u8bc6\u6211\uff01\u201d\u4f17\u4eba\u70b9\u5934\u3002<\/p>\n<p>OF\u8bf4\uff1a\u201c\u5927\u53d4\uff0c\u73b0\u5728\u90fd\u4ec0\u4e48\u5e74\u4ee3\u4e86\uff0c\u7ec6\u80de\u90fd\u8c08\u604b\u7231\u4e86\uff0c\u62cd\u7167\u8fd9\u79cd\u4e8b\u4e0d\u662f\u8d8a\u8001\u5c31\u8d8a\u5389\u5bb3\u7684\uff01\u201d<\/p>\n<p>IN\u8bf4\uff1a\u201c\u6211\u53ef\u4ee5360\u5ea6\u65e0\u6b7b\u89d2\u62cd\u7f8e\u7167\uff01\u201d<\/p>\n<p>OF\u8bf4\uff1a\u201c\u597d\u5de7\u554a\uff0c\u6211\u4e5f\u53ef\u4ee5360\u5ea6\u65e0\u6b7b\u89d2\u62cd\u7f8e\u7167\uff01\u201d<\/p>\n<p>\u2026\u2026<\/p>\n<p>\u5c31\u8fd9\u6837\uff0cIN\u548cOF\u4f60\u4e00\u53e5\u6211\u4e00\u53e5\uff0c\u5435\u5f97\u4e0d\u53ef\u5f00\u4ea4\uff0c\u5b8c\u5168\u6ca1\u6709\u4e2a\u5934\uff0c\u6211\u5b9e\u5728\u770b\u4e0d\u4e0b\u53bb\u4e86\uff0c\u76f4\u63a5\u8d70\u4e0a\u524d\uff0c\u5927\u624b\u4e00\u6446\uff0c\u529d\u67b6\u9053\uff1a\u201c\u5185\u4e2a\uff0c\u4f60\u4eec\u4e8c\u4f4d\uff0c\u5148\u51b7\u9759\u4e0b\uff01\u201d<\/p>\n<p>\u201c\u4f60\u662f\u54ea\u6839\u8471\u554a\uff1f\u201d<\/p>\n<p>\u201c\u6211\u2026\u2026\u5f20\u601d\u806a\uff01\u201d\u8bf4\u5b8c\uff0c\u4e24\u4eba\u8138\u8272\u7f13\u548c\u4e86\u4e9b\uff0c\u6211\u7acb\u5373\u7ee7\u7eed\u8bf4\u9053\uff1a\u201c\u4f60\u4eec\u8fd9\u6837\u4e89\u8bba\u662f\u6ca1\u6709\u4ec0\u4e48\u7ed3\u8bba\u7684\uff0c\u8981\u4e0d\u8fd9\u6837\uff0c\u4f60\u4eec\u76f4\u63a5\u5c31\u628a\u4f60\u4eec\u90a3\u4e2a360\u5ea6\u6280\u672f\u5f53\u573a\u5c55\u793a\u4e0b\uff0c\u6211\u4eec\u8fd9\u4e00\u5708\u89c2\u4f17\u7ed9\u4f60\u4eec\u8bc4\u5224\uff0c\u653e\u5fc3\uff0c\u4f60\u77a7\u6211\u4eec\u6253\u626e\uff0c\u4e00\u770b\u5c31\u662f\u7a0b\u5e8f\u5458\uff0c\u7a0b\u5e8f\u5458\u662f\u51fa\u4e86\u95e8\u7684\u8001\u5b9e\uff0c\u4e00\u5b9a\u4f1a\u8bc4\u5224\u516c\u6b63\u7684\u3002\u201d<\/p>\n<p>IN\u548cOF\u4e00\u8138\u4e0d\u53ef\u4fe1\u7684\u8868\u60c5\u3002<\/p>\n<p>\u6211\u6ca1\u529e\u6cd5\uff0c\u76f4\u63a5\u6293\u4f4f\u65c1\u8fb9\u4eba\u5c31\u95ee\uff1a\u201c\u4f60\u662f\u7a0b\u5e8f\u5458\u5417\uff1f\u201d<\/p>\n<p>\u201c\u6211\u662f\uff0c\u6211\u662f\u817e\u8baf\u7684\uff0c\u6211\u505a\u524d\u7aef\u7684\u3002\u201d<\/p>\n<p>\u201c\u54ce\u5440\uff0c\u597d\u5de7\u554a\uff0c\u6211\u4e5f\u662f\u505a\u524d\u7aef\u7684\uff0c\u6211\u662f\u9605\u6587\u7684\u3002\u201d<\/p>\n<p>\u201c\u6211\u662f\u963f\u91cc\u7684\u2026\u2026\u6211\u4ece\u5317\u4eac\u6765\u7684\u2026\u2026\u6211\u505a\u533a\u5757\u94fe\u7684\uff0c\u6211\u505a\u91d1\u878d\u7684\u2026\u2026\u201d\u5927\u5bb6\u7eb7\u7eb7\u8868\u660e\u4e86\u81ea\u5df1\u7684\u8eab\u4efd\u3002<\/p>\n<p>\u201c\u4f60\u770b\u73b0\u5728\u56f4\u89c2\u7684\u5168\u90e8\u90fd\u662f\u7a0b\u5e8f\u5458\uff0c\u6280\u672f\u7537\uff0c\u7edd\u5bf9\u9760\u8c31\uff0c\u4e0d\u77e5\u4f60\u4eec\u610f\u4e0b\u5982\u4f55\uff1f\u201d<\/p>\n<p>IN\u548cOF\u9762\u9762\u76f8\u89d1\u4e86\u4e00\u4e0b\uff0c\u8bf4\u9053\uff1a\u201c\u597d\u5427\uff0c\u6211\u4eec\u540c\u610f\u4e86\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u4f9d\u6b21\u5c55\u793a\u6211\u4eec\u6280\u80fd\uff0c\u4f60\u4eec\u53ef\u90fd\u8981\u770b\u4ed4\u7ec6\u4e86\u3002\u201d<\/p>\n<p><span class=\"s\">\/\/zxx: \u53cc\u65b9\u63a5\u4e0b\u6765\u4f7f\u51fa\u7684\u6280\u80fd\u6211\u90fd\u52a0\u7c97\u4e86<\/span><\/p>\n<hr>\n<p>\u201cIN\u524d\u8f88\uff0c\u4f60\u662f\u524d\u8f88\uff0c\u9075\u8001\u7231\u5e7c\uff0c\u4f60\u5148\u6765\uff01\u201dOF\u8bf4\u9053\u3002<\/p>\n<p>\u201c\u597d\uff0c\u606d\u656c\u4e0d\u5982\u4ece\u547d\uff01\u201dIN\u56de\u9053\uff0c\u7136\u540e\u5f00\u59cb\u5c55\u793a\u81ea\u5df1\u624d\u827a\uff0c\u53ea\u89c1\u4e00\u4e2a\u8dc3\u8d77\uff0c360\u5ea6\u5927\u56de\u73af\uff0c\u53e3\u4e2d\u558a\u9053\uff1a\u201c\u6211<strong>\u53ef\u4ee5\u679a\u4e3e\u5bf9\u8c61<\/strong>\u3002\u201d\u7136\u540e\u4e00\u987f\u5494\u5494\u5494\u5494\u95ea\u5149\u706f\uff0c\u7136\u540e\u7167\u51fa\u4e86\u4e0b\u9762\u7684\u753b\u9762\uff1a<\/p>\n<pre>var obj = {\n  a: 1,\n  b: [],\n  c: function () {}\n};\nfor (var key in obj) {\n   console.log(key);\n}\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ a\n\/\/ b\n\/\/ c<\/span><\/pre>\n<p>\u201c\u600e\u4e48\u6837\uff0c\u5389\u4e0d\u5389\u5bb3\uff1f\u201d\u56f4\u89c2\u4f17\u4eba\u5567\u5567\u79f0\u8d5e\u3002<\/p>\n<p>\u201c\u5475\u5475\uff01\u201dOF\u51b7\u7b11\u4e86\u4e0b\uff0c\u201c\u8fd9\u6709\u5565\uff0c\u770b\u6211\u7684\uff01\u201d\u542c\u8fd9\u53e3\u6c14\uff0cOF\u8981\u9e1f\u8d77\u4e86\uff0c\u4f17\u4eba\u6295\u6765\u671f\u76fc\u76ee\u5149\u3002<\/p>\n<p>\u53ea\u89c1OF\u4ece\u80cc\u540e\u62bd\u51fa\u4e00\u4e2a40\u7c73\u7684\u76f8\u673a\uff0c\u4e5f\u662f\u4e00\u987f\u5494\u5494\u5494\u5494\uff0c\u7136\u540e\u4e00\u4e2a\u8dc3\u8d77\uff0c360\u5ea6\u5927\u56de\u73af\uff0c\u53ea\u542c\u89c1\u54ce\u5440\u4e00\u58f0\uff0cOF\u6454\u4e86\u4e2a\u5927\u8ddf\u5934\uff0c\u753b\u9762\u5982\u4e0b\uff1a<\/p>\n<pre>var obj = {\n  a: 1,\n  b: [],\n  c: function () {}\n};\nfor (var key of obj) {\n   console.log(key);\n}\n<span style=\"color:red;\">\/\/ \u51fa\u9519\uff1a\n\/\/ Uncaught TypeError: obj is not iterable<\/span><\/pre>\n<p>\u4f17\u4eba\u7eb7\u7eb7\u6447\u5934\uff0c\u5618\u58f0\u56db\u8d77\u3002<\/p>\n<p>IN\u5728\u90a3\u91cc\u54c8\u54c8\u4ef0\u5934\u5927\u7b11\uff1a\u201cOF\u4f60\u80c6\u513f\u8fd8\u771f\u80a5\uff0c\u8fde\u4e2a\u7b80\u5355\u7684\u5bf9\u8c61\u679a\u4e3e\u90fd\u641e\u4e0d\u5b9a\uff0c\u4e5f\u6562\u548c\u6211\u4e89\u9ad8\u4e0b\uff01\u5b9e\u8bdd\u544a\u8bc9\u4f60\uff0c\u6211\u4e0d\u4ec5\u53ef\u4ee5\u679a\u4e3e\u7eaf\u5bf9\u8c61\uff0c\u6211\u8fd8<strong>\u53ef\u4ee5\u679a\u4e3e\u6570\u7ec4<\/strong>\u3002\u201d<\/p>\n<p>\u53ea\u89c1\u4e00\u987f\u64cd\u4f5c\u540e\u6d6e\u73b0\u51fa\u4e0b\u9762\u7684\u753b\u9762\uff1a<\/p>\n<pre>var arr = [3, 5, 7];\nfor (var i in arr) {\n   console.log(i);\n}\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ 0\n\/\/ 1\n\/\/ 2<\/span><\/pre>\n<p>\u4f17\u4eba\u7eb7\u7eb7\u70b9\u5934\u8868\u793aget\u5230\u4e86\u70b9\u3002<\/p>\n<p>\u201c\u5475\u5475\uff01\u201dOF\u51b7\u7b11\u4e86\u4e0b\uff0c\u201c\u8fd9\u6709\u5565\uff0c\u770b\u6211\u7684\uff01\u6211<strong>\u53ef\u4ee5\u8fed\u4ee3\u6570\u7ec4<\/strong>\u3002\u201d\u540c\u6837\u7684\u53e3\u6c14\uff0c\u4e0d\u8fc7\u8fd9\u6b21\u4f17\u4eba\u5df2\u7ecf\u63d0\u524d\u5f00\u59cb\u6447\u5934\u4e86\u3002\u53ea\u89c1\u4ece\u5de6\u5f80\u53f3\u4e00\u987f\u62cd\uff0c\u7136\u540e\u51fa\u73b0\u4e86\u4e0b\u9762\u7684\u753b\u9762\uff1a<\/p>\n<pre>var arr = [3, 5, 7];\nfor (var i of arr) {\n   console.log(i);\n}\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ 3\n\/\/ 5\n\/\/ 7<\/span><\/pre>\n<p>\u56f4\u89c2\u4f17\u4eba\u4f3c\u4e4e\u4e4b\u524d\u6ca1\u89c1\u8fc7\u8fd9\u6837\u7684\u573a\u666f\uff0c\u7eb7\u7eb7\u4ea4\u5934\u63a5\u8033\u3002<\/p>\n<p>\u4e5f\u4e0d\u7981\u6fc0\u8d77\u4e86\u6211\u81ea\u5df1\u7684\u5174\u8da3\uff1a\u201c\u6709\u610f\u601d\uff01<code>for..of<\/code>\u539f\u6765\u662f\u76f4\u63a5\u8f93\u51fa\u4e86\u6570\u7ec4\u7684\u503c\u3002\u53ea\u662f\u2026\u2026\u201d<\/p>\n<p>\u201c\u54c8\u54c8\uff01\u201dIN\u53c8\u5f97\u610f\u5730\u7b11\u4e86\u8d77\u6765\uff0c\u201cOF\u554aOF\uff0c\u4f60\u8d70\u7684\u662f\u54ea\u4e00\u51fa\u554a\uff0c\u4f60\u53ea\u80fd\u2018\u679a\u4e3e\u2019\u51fa\u6570\u7ec4\u7684\u503c\uff0c\u6570\u7ec4\u7684\u7d22\u5f15\u4f60\u5c31\u8fd9\u6837\u653e\u5f03\u4e86\uff1f\u4f60\u770b\u6211\uff0c\u80fd\u8f93\u51fa\u7d22\u5f15\uff0c\u4e5f\u80fd\u8f93\u51fa\u503c\u3002\u201d<\/p>\n<pre>var arr = [3, 5, 7];\nfor (var i in arr) {\n   console.log(i, arr[i]);\n}\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ 0 3\n\/\/ 1 5\n\/\/ 2 7<\/span><\/pre>\n<p>\u4f17\u4eba\u518d\u6b21\u5567\u5567\u79f0\u8d5e\uff0c\u770b\u6765<code>for..in<\/code>\u80dc\u51fa\u7684\u6982\u7387\u8f83\u5927\u554a\u3002<\/p>\n<p>IN\u4f3c\u4e4e\u6709\u4e9b\u5f97\u610f\u8fc7\u5934\uff0c\u7ee7\u7eed\u5f97\u745f\u9053\uff1a\u201c\u6211\u4e0d\u4ec5\u53ef\u4ee5\u679a\u4e3e\u6570\u7ec4\u81ea\u8eab\u3002\u6570\u7ec4\u7684\u539f\u578b\u5bf9\u8c61\uff0c\u4ee5\u53ca\u6570\u7ec4\u5bf9\u8c61\u672c\u8eab\u5c5e\u6027\u503c\uff0c\u6211\u90fd\u53ef\u4ee5\u679a\u4e3e\u51fa\u6765\uff01OF\uff0c\u4f60\u53ef\u4ee5\u5417\uff1f\u201d<\/p>\n<pre>Object.prototype.objCustom = function() {}; \nArray.prototype.arrCustom = function() {};\n\nvar arr = [3, 5, 7];\narr.foo = 'hello';\n\nfor (var i in arr) {\n   console.log(i);\n}\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ 0\n\/\/ 1\n\/\/ 2\n\/\/ foo\n\/\/ arrCustom\n\/\/ objCustom<\/span><\/pre>\n<p>\u8fd9\u4e0d\u5f97\u745f\u8fd8\u597d\uff0c\u8fd9\u4e00\u5f97\u745f\u53cd\u800c\u8ba9OF\u6293\u4f4f\u4e86\u5c0f\u628a\u67c4\uff1a\u201c\u54df\u54df\u54df\uff0c\u8fde\u539f\u578b\u5bf9\u8c61\u90fd\u51fa\u6765\u4e86\uff0c\u8fd9\u5b9e\u9645\u5de5\u4f5c\u5f00\u53d1\uff0c\u8fd9\u4e9b\u5bf9\u8c61\u5f88\u53ef\u80fd\u662f\u4e0d\u9700\u8981\u7684\uff0c\u4f60\u4e0d\u7ba1\u4e09\u4e03\u4e8c\u5341\u4e00\u5168\u90e8\u679a\u4e3e\u51fa\u6765\uff0c\u4f60\u5c31\u4e0d\u62c5\u5fc3\u51fa\u95ee\u9898\u5417\uff1f\u201d<\/p>\n<p>\u8fd9\u4e00\u95ee\u4e00\u77ac\u95f4\u8ba9IN\u8bed\u585e\uff0c\u597d\u5728\u8fd8\u7b97\u673a\u7075\uff0c\u7acb\u9a6c\u60f3\u5230\u4e00\u4e2a\u4e1c\u897f\uff0c\u5047\u88c5\u6de1\u5b9a\u56de\u590d\u9053\uff1a\u201c\u8fd9\u4e2a\u4e0d\u7528\u62c5\u5fc3\uff0c\u6211\u6709\u53e6\u5916\u4e00\u4ef6\u5229\u5668\uff0c\u540d\u4e3a<code>hasOwnProperty<\/code>\uff0c\u53ef\u4ee5\u907f\u514d\u51fa\u73b0\u4f60\u8bf4\u7684\u95ee\u9898\uff0c\u5927\u5bb6\u8bf7\u770b~\u201d<\/p>\n<pre>Object.prototype.objCustom = function() {}; \nArray.prototype.arrCustom = function() {};\n\nvar arr = [3, 5, 7];\narr.foo = 'hello';\n\nfor (var i in arr) {\n   if (arr.<span style=\"color:#cd0000;\">hasOwnProperty<\/span>(i)) {\n    console.log(i);\n  }\n}\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ 0\n\/\/ 1\n\/\/ 2\n\/\/ foo<\/span><\/pre>\n<p>OF\u5148\u662f\u4e00\u60ca\uff0cIN\u8fd9\u8001\u5bb6\u4f19\u8fd8\u6709\u8fd9\u4e00\u624b\uff0c\u53ef\u5b9a\u775b\u4e00\u770b\uff0c\u54c8\u54c8\u5927\u7b11\u4e86\u8d77\u6765\uff0c\u201c\u54df\u54df\u54df\uff0c\u4f60\u770b\u770b\u4f60\uff0c\u6570\u7ec4\u672c\u8eab\u7684\u5c5e\u6027\u770b\u6765\u4f60\u662f\u600e\u4e48\u4e5f\u6446\u8131\u4e0d\u6389\u4e86\u54e6\uff01\u201d<\/p>\n<p>IN\u4e00\u7785\uff0c\u54c7\u64e6\uff0c\u600e\u4e48\u8fd8\u6709\u4e2a<code>foo<\/code>\uff0c\u987f\u65f6\u5c34\u5c2c\u4e0d\u5df2\uff0c\u51b7\u6c57\u56db\u8d77\uff0c\u652f\u652f\u543e\u543e\uff0c\u8e66\u4e86\u4e00\u53e5\uff1a\u201c\u8fd9\u79cd\u60c5\u51b5\uff0c\u6211\u2026\u2026\u6211\u53ef\u4ee5\u8ba9\u6211\u7684\u597d\u670b\u53cb<code>forEach<\/code>\u8fc7\u6765\u5e2e\u5fd9\uff0c\u4ed6\u7684\u8868\u73b0\u662f\u8fd9\u6837\u7684~\u201d<\/p>\n<pre>Object.prototype.objCustom = function() {}; \nArray.prototype.arrCustom = function() {};\n\nvar arr = [3, 5, 7];\narr.foo = 'hello';\n\narr.forEach(function (value, i) {\n  console.log(i);\n});\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ 0\n\/\/ 1\n\/\/ 2<\/span><\/pre>\n<p>\u8bf4\u5b8cIN\u7acb\u9a6c\u8138\u8272\u597d\u8f6c\uff0c\u9762\u9732\u5fae\u7b11\uff0c\u6697\u81ea\u5e86\u5e78\u81ea\u5df1\u4eba\u8109\u5e7f\uff0c\u4eba\u673a\u7075\u3002\u8c01\u77e5OF\u4e0d\u65ad\u54c8\u54c8\u5927\u7b11\uff0c\u7b11\u5f97IN\u5fc3\u91cc\u6bdb\u6bdb\u7684\uff0c\u96be\u9053\u53c8\u8981\u641e\u51fa\u4ec0\u4e48\u5e7a\u86fe\u5b50\u3002<\/p>\n<p>\u53ea\u89c1OF\u6162\u60a0\u60a0\u5411\u524d\u8e31\u4e86\u4e24\u6b65\uff0c\u4e00\u8138\u8f7b\u8511\u5730\u8bf4\u9053\uff1a\u201cforEach\uff0c\u6211\u77e5\u9053\u7684\uff0c\u5475\u5475\u5475\uff0c\u524d\u6bb5\u65f6\u95f4\u6211\u4eec\u521a\u7b14\u8bd5\u8fc7\uff0c\u6211\u7684\u624b\u4e0b\u8d25\u5c06\uff0c\u4e0d\u503c\u4e00\u63d0\u3002\u201d\u7136\u540e\u5bf9\u7740\u56f4\u89c2\u7684\u7fa4\u4f17\u5927\u58f0\u8bf4\u9053\uff1a\u201c\u8fd9\u4e2aforEach\u554a\uff0c\u53ea\u80fd\u904d\u5386\u6570\u7ec4\uff0c\u600e\u4e48\u80fd\u8ddf\u6211\u6bd4\uff1b\u5c31\u7b97\u6bd4\u8bd5\u2018\u904d\u5386\u2019\u6570\u7ec4\uff0cforEach\u8ddf\u6211\u6bd4\u4e5f\u662f\u900a\u8272\u51e0\u5206\u7684\u3002\u4f60\u4eec\u53ef\u80fd\u4e0d\u77e5\u9053\u5427\uff0cforEach\u904d\u5386\u6570\u7ec4\u7684\u65f6\u5019\u662f\u65e0\u6cd5<code>break<\/code>\u6216\u8005<code>return false<\/code>\u4e2d\u65ad\u7684\u3002\u6bd4\u65b9\u8bf4~\u201d<\/p>\n<pre>var arr = [3, 5, 7];\n\narr.forEach(function (value) {\n  console.log(value);\n  if (value == 5) {\n    return false;\n  }\n});\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ 3\n\/\/ 5\n\/\/ 7<\/span><\/pre>\n<p>\u201c\u5927\u5bb6\u770b\u5230\u6ca1\uff0c<code>return false<\/code>\u6839\u672c\u5c31\u6ca1\u4f5c\u7528\uff0c\u4e00\u76f4\u5faa\u73af\u5230\u5e95\u3002\u201d\u4f17\u4eba\u7eb7\u7eb7\u70b9\u5934\u8868\u793a\u8ba4\u540c\uff0cOF\u7ee7\u7eed\u8bf4\u9053\uff1a\u201c\u90a3\u6211\u5c31\u4e0d\u4e00\u6837\u4e86\uff0c\u6211\u76f4\u63a5\u4e00\u4e2a<code>break<\/code>\u5c31<strong>\u80fd\u4e2d\u65ad\u5faa\u73af<\/strong>\uff0c\u53ef\u8c13\u80fd\u8fdb\u80fd\u51fa\uff0c\u6211\u7ed9\u5927\u5bb6\u8868\u6f14\u4e0b\u3002\u201d<\/p>\n<p>\u53ea\u89c1OF\u8170\u95f4\u62bd\u51fa\u4e00\u628a40CM\u957f\u5200\uff0c\u5bf9\u7740\u81ea\u5df1\u8170\u90e8\u76f4\u63a5\u5c31\u780d\u554a\uff0c\u773c\u775b\u90fd\u4e0d\u7728\u4e00\u4e0b\uff0c\u4f17\u4eba\u7eb7\u7eb7\u4fa7\u76ee\u4e0d\u5fcd\u76f4\u89c6\uff0c\u80c6\u5927\u7684\u4eba\u7784\u4e86\u7784\uff0c\u770b\u5230\u4e86\u4e0b\u9762\u7684\u753b\u9762\uff1a<\/p>\n<pre>var arr = [3, 5, 7];\n\nfor (let value of arr) {\n  console.log(value);\n  if (value == 5) {\n    break;\n  }\n}\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ 3\n\/\/ 5<\/span><\/pre>\n<p>\u5927\u5bb6\u4e00\u770b\uff0c\u679c\u7136\u6570\u7ec4\u6700\u540e\u4e00\u9879<code>7<\/code>\u6ca1\u6709\u8f93\u51fa\uff0c\u679c\u7136\u5faa\u73af\u4e2d\u65ad\u4e86\uff0c\u800c\u4e14\u2026\u2026\u5927\u5bb6\u4ed4\u7ec6\u770b\u4e86\u770b\uff0cOF\u867d\u7136\u780d\u4e86\u81ea\u5df1\u4e00\u5200\uff0c\u4e0d\u8fc7\u770b\u4e0a\u53bb\u5e76\u6ca1\u6709\u4efb\u4f55\u4f24\u5bb3\uff01\u4f17\u4eba\u4e0d\u7981\u7eb7\u7eb7\u559d\u5f69\u9f13\u638c\u8d77\u6765\u3002<\/p>\n<p>IN\u5728\u4e00\u65c1\u770b\u50bb\u773c\u4e86\uff0cOF\u5219\u5f97\u610f\u6d0b\u6d0b\uff0c\u5f00\u59cb\u4e58\u80dc\u8ffd\u51fb\uff1a\u201c\u54ce\u5440\uff0c\u6709\u4e9b\u4eba\u554a\uff0c\u6ca1\u89c1\u8fc7\u4e16\u9762\uff0c\u4e0d\u77e5\u9053\u52a8\u6f2b\u7684\u4e16\u754c\u91cc\u5148\u624b\u90fd\u662f\u8f93\u561b\uff0c\u54c8\u54c8\u54c8\u3002\u73b0\u5728\uff0c\u662f\u65f6\u5019\u5c55\u73b0\u771f\u6b63\u7684\u6280\u672f\u4e86\uff01\u201d\u53ea\u89c1OF\u53e3\u4e2d\u5ff5\u5ff5\u6709\u8bcd\uff0c\u7a81\u7136\uff0c\u624b\u4e2d\u767d\u5149\u4e00\u95ea\uff0c\u51fa\u73b0\u4e86\u51e0\u4ef6\u5b9d\u7269\uff0c\u4f17\u4eba\u773c\u775b\u90fd\u770b\u76f4\u4e86\u3002<\/p>\n<p>\u53ea\u89c1OF\u4e0d\u7d27\u4e0d\u6162\u5730\u8bf4\u9053\uff1a\u201c\u6d12\u5bb6\u6211\u7684\u6280\u80fd\u53eb\u505a\u2018\u8fed\u4ee3\u2019\uff0c\u8ddfIN\u90a3\u79cd\u2018\u679a\u4e3e\u2019\u4e0d\u662f\u4e00\u4e2alevel\u7684\u3002\u6211\u5462\u4e0d\u4ec5\u53ef\u4ee5\u8fed\u4ee3\u6570\u7ec4\uff0c\u6211\u8fd8\u53ef\u4ee5\u76f4\u63a5<strong>\u8fed\u4ee3\u5b57\u7b26\u4e32<\/strong>\uff0c\u5927\u5bb6\u53ef\u4ee5\u56f4\u8fc7\u6765\u770b\u4e00\u770b\u554a\u2026\u2026\u201d<\/p>\n<p>\u6211\u51d1\u4e0a\u524d\u4e00\u770b\uff0c\u679c\u7136\u53ef\u4ee5\u554a\uff01<\/p>\n<pre>let str = 'boo';\n\nfor (let value of str) {\n  console.log(value);\n}\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ \"b\"\n\/\/ \"o\"\n\/\/ \"o\"<\/span><\/pre>\n<p>IN\u652f\u652f\u543e\u543e\u8bf4\u4e0d\u51fa\u8bdd\u6765\u4e86\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u81ea\u5df1\u771f\u7684\u4e0d\u652f\u6301\uff0c\u5f3a\u884c\u6267\u884c\u4e5f\u6ca1\u53cd\u5e94\uff08\u66f4\u65b0\uff1a\u8fd9\u662f\u662f\u56e0\u4e3aIN\u7684\u8bb0\u5fc6\u8fd8\u505c\u7559\u5230\u8fc7\u53bb\uff0c\u66fe\u7ecf\u7684\u81ea\u5df1\u662f\u4e0d\u652f\u6301\u5b57\u7b26\u4e32\u904d\u5386\uff0cIE9+\u4e4b\u540e\u624d\u652f\u6301\uff09\u3002<\/p>\n<p>OF\u7ee7\u7eed\u8bf4\u9053\uff1a\u201c\u6211\u8fd8\u53ef\u4ee5\u76f4\u63a5<strong>\u8fed\u4ee3arguments\u7c7b\u6570\u7ec4\u5bf9\u8c61<\/strong>\uff0c\u4e14\u770b~\u201d<\/p>\n<pre>(function() {\n  for (let argument of arguments) {\n    console.log(argument);\n  }\n})(1, 2, 3);\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ 1\n\/\/ 2\n\/\/ 3<\/span><\/pre>\n<p>\u201c\u5594\u5662\uff0c\u8fd9\u4e2a\u597d\uff01\u201d\u56f4\u89c2\u7684\u7a0b\u5e8f\u5458\u4eec\u7eb7\u7eb7\u7ad6\u8d77\u4e86\u5927\u62c7\u6307\u3002<\/p>\n<p>\u201c\u8fd8\u6ca1\u5b8c\u5462\uff0c\u563b\u563b\u2026\u2026\u6211\u8fd8\u53ef\u4ee5<strong>\u8fed\u4ee3NodeList\u8fd9\u7c7bDOM\u96c6\u5408<\/strong>\uff0c\u65e0\u9700<code>[].slice.call()<\/code>\uff0c\u4e5f\u4e0d\u9700\u8981<code>Array.from()<\/code>\u8fdb\u884c\u6570\u7ec4\u8f6c\u5316\uff0c\u6211\u53ef\u4ee5\u76f4\u63a5\u7528\u8d77\u6765~\u201d<\/p>\n<pre>let elements = document.querySelectorAll('body');\n\nfor (let element of elements) {\n  console.log(element.tagName);\n}\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ \"BODY\"<\/span><\/pre>\n<p>\u201c\u5594\u54e6\u54e6\u5594\uff0c\u8fd9\u4e2a\u66f4\u597d\uff01\u201d\u56f4\u89c2\u7684\u7a0b\u5e8f\u5458\u5f00\u59cb\u6b22\u547c\uff0c\u5f00\u59cb\u6fc0\u52a8\uff0c\u4eba\u7fa4\u6d8c\u52a8\uff0c\u5df2\u7ecf\u628aIN\u6324\u5230\u4e86\u5708\u5916\u3002<\/p>\n<p>IN\u5728\u5708\u5916\uff0c\u5927\u58f0\u75be\u558a\uff0c\u201c\u6211\u2026\u2026\u6211\u4e5f\u53ef\u4ee5\u904d\u5386\u7c7b\u6570\u7ec4\u7684\u2026\u2026\u201d\uff0c\u53ea\u662f\u4e00\u4e2a\u4eba\u7684\u58f0\u97f3\u5982\u4f55\u8ddf\u4eba\u7fa4\u6bd4\uff0c\u65e9\u5df2\u6e6e\u6ca1\u5728\u4f17\u4eba\u7684\u558a\u53eb\u58f0\u4e2d\u3002<\/p>\n<p>\u6211\u5fc3\u60f3\uff1a\u770b\u6765\uff0c\u8fd9\u573a\u6bd4\u8bd5\uff0c\u5982\u679c\u6ca1\u6709\u5947\u8ff9\u7684\u8bdd\uff0c<code>for..of<\/code>\u5e94\u8be5\u5c31\u8d62\u4e86\uff01\u8eab\u4e3a\u53d1\u8d77\u8fd9\u573a\u6bd4\u8bd5\u7684\u6211\u5df2\u7ecf\u6253\u7b97\u5ba3\u5e03<code>for..of<\/code>\u4e0b\u534a\u573a\u7ffb\u76d8\u83b7\u80dc\uff0c\u7ed3\u679c<code>for..of<\/code>\u7ee7\u7eed\u4e0d\u4f9d\u4e0d\u9976\u79c0\u81ea\u5df1\u6280\u80fd\u3002<\/p>\n<p>\u201c\u6211\u8fd8\u53ef\u4ee5<strong>\u8fed\u4ee3\u7c7b\u578b\u6570\u7ec4<\/strong>~\u201d<\/p>\n<pre>let typeArr = new Uint8Array([0x00, 0xff]);\n\nfor (let value of typeArr) {\n  console.log(value);\n}\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ 0\n\/\/ 255<\/span><\/pre>\n<p>\u201c\u6211\u8fd8\u53ef\u4ee5<strong>\u8fed\u4ee3Map<\/strong>~\u201d<\/p>\n<pre>let mapData = new Map([['a', 1], ['b', 2], ['c', 3]]);\n\nfor (let [key, value] of mapData) {\n  console.log(value);\n}\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ 1\n\/\/ 2\n\/\/ 3<\/span><\/pre>\n<p>\u201c\u6211\u8fd8\u53ef\u4ee5<strong>\u8fed\u4ee3Set<\/strong>~\u201d<\/p>\n<pre>let setData = new Set([1, 1, 2, 2, 3, 3]);\n\nfor (let value of setData) {\n  console.log(value);\n}\n<span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1a\n\/\/ 1\n\/\/ 2\n\/\/ 3<\/span><\/pre>\n<p>\u201c\u6211\u8fd8\u53ef\u4ee5<strong>\u8fed\u4ee3generators<\/strong>\u2026\u2026\u201d<\/p>\n<p>\u5b8c\u4e86\u5b8c\u4e86\uff0c\u5df2\u7ecf\u5b8c\u5168\u6210\u4e86<code>for..of<\/code>\u4e13\u573a\u4e86\uff0c\u6211\u770b\u4e86\u770b\u4e00\u65c1\u7070\u5934\u571f\u8138\uff0c\u6beb\u65e0\u751f\u6c14\u7684<code>for..in<\/code>\uff0c\u4e0d\u7981\u62c5\u5fe7\uff0c\u8fd9\u573a\u6bd4\u8bd5\u4f1a\u4e0d\u4f1a\u8ba9<code>for..in<\/code>\u6000\u7591\u4eba\u751f\uff0c\u4ece\u6b64\u4eceCJ\u5708\u6d88\u5931\u554a\uff0c\u751a\u81f3\u76f4\u63a5\u4ece\u5927\u60a6\u57ce\u4e00\u8dc3\u800c\u4e0b\u2026\u2026\u6211\u8d8a\u60f3\u8d8a\u540e\u6015\uff0c\u8d76\u5feb\u6253\u4f4f\uff1a\u201c\u591f\u4e86\u591f\u4e86\uff01\u201d<\/p>\n<p>OF\u89c1\u6211\u6253\u65ad\u5176\u8868\u6f14\u6709\u4e9b\u4e0d\u5f00\u5fc3\uff0c\u6211\u5c31\u8bf4\u4e86\u8fd9\u4e48\u4e00\u53e5\uff1a\u201c\u5c11\u4fa0\uff0c\u5f97\u9976\u4eba\u5904\u4e14\u9976\u4eba\u3002\u6211\u4eec\u5728\u573a\u6240\u6709\u4eba\u90fd\u8ba4\u4e3a\u4f60\u6b66\u827a\u9ad8\u5f3a\uff0c\u76f8\u6bd4<code>for..in<\/code>\u8981\u66f4\u80dc\u4e00\u7b79\u3002\u201dOF\u7acb\u9a6c\u8138\u8272\u597d\u4e86\u5f88\u591a\uff0c\u4e00\u8138\u8dbe\u9ad8\u6c14\u6602\u3002<\/p>\n<p>\u6211\u5e73\u751f\u6700\u770b\u4e0d\u60ef\u90a3\u4e9b\u62fd\u62fd\u7684\u4eba\uff0cOF\u548cIN\u90fd\u4e0d\u77e5\u9053\u8c26\u900a\uff0c\u6211\u90fd\u6ca1\u4ec0\u4e48\u597d\u611f\u3002\u4e0d\u8fc7\u8eab\u4e3a\u88c1\u5224\uff0c\u8fd8\u662f\u8981\u516c\u6b63\uff0c\u4e8e\u662f\uff0c\u6211\u5c31\u8bf4\u9053\uff1a\u201c\u5728\u5ba3\u5e03\u6bd4\u8d5b\u7ed3\u679c\u4e4b\u524d\uff0c\u6211\u5148\u5bf9\u4e24\u4f4d\u7cbe\u5f69\u7684\u6bd4\u8bd5\u505a\u4e2a\u603b\u7ed3\u3002\u5bf9\u4e8e\u7eaf\u5bf9\u8c61\u7684\u904d\u5386\uff0c<code>for..in<\/code>\u8981\u5389\u5bb3\u4e00\u4e9b\uff0c\u5927\u5bb6\u76f8\u4fe1\u90fd\u770b\u5230\u4e86\uff1b\u5bf9\u4e8e\u6570\u7ec4\u904d\u5386\uff0c\u5982\u679c\u4e0d\u9700\u8981\u77e5\u9053\u7d22\u5f15\uff0c<code>for..of<\/code>\u8fed\u4ee3\u66f4\u5408\u9002\uff0c\u56e0\u4e3a\u8fd8\u53ef\u4ee5\u4e2d\u65ad\uff1b\u5982\u679c\u9700\u8981\u77e5\u9053\u7d22\u5f15\uff0c\u5219<code>forEach()<\/code>\u66f4\u5408\u9002\uff1b\u5bf9\u4e8e\u5176\u4ed6\u5b57\u7b26\u4e32\uff0c\u7c7b\u6570\u7ec4\uff0c\u7c7b\u578b\u6570\u7ec4\u7684\u8fed\u4ee3\uff0c\u867d\u7136<code>for..in<\/code>\u4e5f\u6709\u8fd9\u65b9\u9762\u80fd\u529b\uff0c\u53ea\u662f\u4ece\u4eca\u5929\u7684\u6bd4\u8d5b\u573a\u9762\u6765\u770b\uff0c<code>for..of<\/code>\u66f4\u5360\u4e0a\u98ce\uff0c\u56e0\u6b64\uff0c\u6211\u5ba3\u5e03\uff0c\u672c\u6b21\u6bd4\u8d5b\u7684\u83b7\u80dc\u8005\u662f\u2026\u2026\u201d<\/p>\n<p>OF\u5728\u821e\u53f0\u4e2d\u592e\uff0c\u6d0b\u6d0b\u5f97\u610f\uff0c\u51c6\u5907\u4eab\u53d7\u5ba3\u5e03\u80dc\u5229\u65f6\u5019\u7684\u8363\u5149\uff0c\u5c31\u5728\u6b64\u65f6\uff0c\u4eba\u7fa4\u4e00\u9635\u54d7\u7136\uff0c\u4ec0\u4e48\u60c5\u51b5\uff0c\u5367\u69fd\uff0c\u4e00\u7fa4\u8840\u5c0f\u677f\u7a81\u7136\u8d70\u4e86\u8fc7\u6765\u3002\u201c\u5361\u54c7\u4f0a\u2026\u2026\u201d\u4f17\u4eba\u4e0d\u7981\u9f50\u547c\uff0c\u773c\u775b\u90fd\u653e\u51fa\u4e8640\u74e6\u706f\u6ce1\u4eae\u5ea6\u7684\u5149\uff0c\u8eab\u5b50\u76f4\u63a5\u90fd\u8f6f\u6389\u4e86\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201808\/xxb-group.jpg\" width=\"180\" height=\"111\" alt=\"\u8840\u5c0f\u677f\u4eec\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u201c\u8840\u5c0f\u677f\uff0c\u4f60\u6765\u5f97\u6b63\u597d\uff0c\u6211\u4eec\u6b63\u5728\u7ed9<code>for..in<\/code>\u548c<code>for..of<\/code>\u8bc4\u5224\u8c01\u62cd\u7167\u6280\u672f\u597d\uff0c\u6709\u8d44\u683c\u53ef\u4ee5\u505a\u4f60\u7684\u5fa1\u7528\u6444\u5f71\u5e08\u3002\u201d<\/p>\n<p>\u7ed3\u679c\u8840\u5c0f\u677f\u7528\u8d85\u840c\u7684\u5c0f\u5976\u97f3\u56de\u590d\u6211\uff1a\u201c\u5e05\u6c14\u7684\u5c0f\u54e5\u54e5\uff0c\u53ef\u4e0d\u53ef\u4ee5\u6211\u4eec\u81ea\u5df1\u9009\uff1f\u201d<\/p>\n<p>\u201c\u5f53\u7136\uff0c\u5f53\u7136\u53ef\u4ee5\uff01\u4f60\u9009\uff0c\u6211\u60f3IN\u548cOF\u4e24\u4f4d\u5927\u4eba\u5e94\u8be5\u4e0d\u4f1a\u6709\u4efb\u4f55\u610f\u89c1\u7684\u3002\u201d<\/p>\n<p>\u201c\u5bf9\u7684\uff0c\u6ca1\u6709\u5f02\u8bae\u3002\u201d\u81ea\u4fe1\u7684OF\u7387\u5148\u9644\u548c\u3002<\/p>\n<p>\u201c\u6211\u4e5f\u6ca1\u610f\u89c1\u3002\u201d\u8fdc\u5904\u7684IN\u968f\u4fbf\u4e3e\u4e86\u4e2a\u624b\u65e0\u7cbe\u6253\u91c7\u56de\u590d\u9053\u3002<\/p>\n<p>\u201c\u90a3\u597d\uff01\u201d\u53ea\u89c1\u8840\u5c0f\u677f\u8bf4\u5b8c\uff0c\u8d70\u5230\u4e86<code>for..in<\/code>\u90a3\u91cc\uff0c\u4e3e\u8d77\u4e86<code>for..in<\/code>\u7684\u53cc\u624b\uff0c\u8bf4\u9053\uff1a\u201c\u6211\u8981<code>for..in<\/code>\u505a\u6211\u7684\u6444\u5f71\u5e08\uff01\u201d<\/p>\n<p>\u201c\u554a\uff1f\uff1f\uff1f\uff1f\u201d\u4f17\u4eba\u4e0b\u5df4\u90fd\u60ca\u5f97\u6389\u5728\u4e86\u5730\u4e0a\uff0c\u201c\u4e3a\u5565\uff1f\uff1f\u201d<\/p>\n<p>\u201c\u90a3\u4e2a\uff0c\u90a3\u4e2a\u2026\u2026\u201d\u8840\u5c0f\u677f\u840c\u5976\u97f3\u56de\u7b54\u9053\uff0c\u201c\u8fd9\u6b21\u7684\u7167\u7247\u8981\u5728\u5fae\u8f6f\u540d\u4e3aIE\u7684\u6742\u5fd7\u548c\u7f51\u7ad9\u4e0a\u5c55\u793a\uff0c<code>for..of<\/code>\u5927\u4eba\u867d\u7136\u6280\u80fd\u66f4\u5e7f\uff0c\u4f46\u662f\u6bd5\u7adf\u662fES6\u65b0\u7279\u6027\uff0cIE\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\uff0c\u56e0\u6b64\uff0c\u8fd9\u6b21\u6211\u9009\u517c\u5bb9\u6027\u66f4\u597d\u7684<code>for..in<\/code>\uff01\u201d<\/p>\n<p>\u7136\u540e\uff0c\u4f17\u4eba\u5c31\u773c\u7741\u7741\u770b\u7740<code>for..in<\/code>\u5728\u4f17\u591a\u840c\u840c\u7684\u8840\u5c0f\u677f\u7684\u5305\u56f4\u4e2d\u79bb\u5f00\u4e86\uff01\u800c<code>for..of<\/code>\u53cc\u624b\u6491\u5730\u5f52\u5728\u51b0\u51b7\u7684\u5730\u9762\u4e0a\uff0c\u7559\u4e0b\u4e86\u60b2\u4f24\u7684\u6cea\u6c34\u3002<\/p>\n<p>\u201c\u5509\u2026\u2026\u201d\u4f17\u4eba\u7eb7\u7eb7\u53f9\u606f\uff0c\u201c\u4e16\u4e8b\u96be\u6599\u554a\uff01\u201d\u7136\u540e\u4eba\u7fa4\u9010\u6e10\u6563\u5f00\u4e86\u3002<\/p>\n<p>\u6211\u9a7b\u8db3\u4e86\u7247\u523b\uff0c\u4e5f\u65e0\u80fd\u4e3a\u529b\uff0c\u51c6\u5907\u79bb\u5f00\uff0c\u7a81\u7136\u60f3\u5230\u4e00\u4ef6\u4e8b\u60c5\uff0c\u6211\u4e00\u770b\u624b\u673a\uff0c\u6211\u62c9\u4e2a\u64e6\uff0c\u51fa\u95e8\u5230\u73b0\u5728\u5df2\u7ecf\u8fc7\u53bb1\u4e2a\u5c0f\u65f660\u5206\u949f\u4e86\uff01\u60f3\u5230\u665a\u4e0a\u723d\u8106\u7684\u6413\u8863\u677f\uff0c\u6211\u4e5f\u53cc\u624b\u6491\u5730\u5f52\u5728\u51b0\u51b7\u7684\u5730\u9762\u4e0a\uff0c\u7559\u4e0b\u4e86\u60b2\u4f24\u7684\u6cea\u6c34\u3002<\/p>\n<p>\u6b64\u523b\uff0c\u504c\u5927\u7684\u5c55\u9986\u4e2d\u592e\uff0c\u6709\u4e24\u4eba\u60b2\u4f24\u7684\u4eba\u513f\uff0c\u4ed6\u4eec\u7684\u6cea\u6c34\uff0c\u8ba9\u4eca\u5e74\u7684ChinaJoy\u663e\u5f97\u683c\u5916\u5f97\u52a8\u4eba\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/1f341.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p><strong>\u53c2\u8003\u6587\u7ae0<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Statements\/for...of\" rel=\"noopener nofollow\" target=\"_blank\">MDN for&#8230;of<\/a><\/li>\n<\/ul>\n<p>\u611f\u8c22\u9605\u8bfb\uff0c\u5982\u679c\u4f60\u89c9\u5f97\u6545\u4e8b\u5199\u5f97\u4e0d\u9519\uff0c\u6b22\u8fce\u5206\u4eab\u7ed9\u5176\u4ed6\u5c0f\u4f19\u4f34\u4e00\u8d77\u6765\u8fc7\u6765\u56f4\u89c2<code>for..in<\/code>\u548c<code>for..of<\/code>\u5435\u67b6\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/1f603.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=7908\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=7908<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201808\/for-in-of-thumb.jpg\" width=\"161\" height=\"100\" alt=\"\u6587\u7ae0\u7f29\u7565\u56fe\" class=\"alignright thumb size-medium\" \/> <\/p>\n<p>\u4eca\u5929\u5929\u6c14\u4e0d\u9519\uff0c\u7792\u7740\u8001\u5a46\u53bb\u53c2\u52a0ChinaJoy\uff0c\u563f\u563f\uff0c\u597d\u591a\u5468\u8fb9\uff0c\u563f\u563f\uff0c\u597d\u591a\u840c\u59b9\u5b50\u3002\u7a81\u7136\uff0c\u65c1\u8fb9\u4e00\u4e2a\u6234\u773c\u955c\u7684\u5c0f\u80d6\u5b50\u4e00\u58f0\u5927\u53eb\uff1a\u201c\u770b\uff0cfor..in\u548cfor..of\u5728\u90a3\u91cc\u5435\u67b6\uff01\u201d<\/p>\n<p>\u6211\u987a\u7740\u671b\u53bb\uff0c\u53ea\u89c12\u70b9\u949f\u65b9\u5411\u6709\u4e00\u7fa4\u7a7f\u7740\u683c\u5b50\u886b\u80cc\u7740\u7535\u8111\u5305\u7684\u4eba\u5728\u56f4\u89c2\u4ec0\u4e48\uff0c\u6211\u7acb\u9a6c\u53d1\u73b0\u4e8b\u60c5\u4e0d\u7b80\u5355\uff0c\u5c31\u8ddf\u7740\u8fc7\u53bb\u56f4\u89c2\uff0c\u7ed3\u679c\u610f\u60f3\u4e0d\u5230\u7684\u4e8b\u60c5\u53d1\u751f\u4e86\u2026\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1284],"tags":[904,1297,1298,794,1300,1301,1299],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/7908"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=7908"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/7908\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=7908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=7908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=7908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}