{"id":1656,"date":"2017-07-17T17:22:03","date_gmt":"2017-07-17T09:22:03","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=1656"},"modified":"2017-07-17T17:22:03","modified_gmt":"2017-07-17T09:22:03","slug":"symbols-%e5%be%aa%e7%8e%af%e8%bf%ad%e4%bb%a3%e4%b8%8e-for-in-%e8%bf%ad%e4%bb%a3","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=1656","title":{"rendered":"Symbols \u5faa\u73af\u8fed\u4ee3\u4e0e for&#8230;in \u8fed\u4ee3"},"content":{"rendered":"<p>\n\t\u524d\u9762\u8bf4\u4e86&nbsp;symbol \u662f\u4e00\u79cd\u6570\u636e\u7c7b\u578b\u3002\u65e2\u7136\u662f\u4e00\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u90a3\u4e48\u5b83\u5c31\u5e94\u8be5\u652f\u6301\u5faa\u73af\u8fed\u4ee3\u7b49\u8ba1\u7b97\u3002\u90a3\u4e48 symbol \u662f\u5982\u4f55\u8fdb\u884c\u8fed\u4ee3\u7684\u5462\uff1f\u672c\u6587\u5c06\u4e3a\u4f60\u63ed\u5f00\u7b54\u6848\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"Symbols \u4e0e for...in \u8fed\u4ee3\" src=\"http:\/\/img.blog.csdn.net\/20170717105715847\" style=\"width: 862px;height: 469px\" \/>\n<\/p>\n<h2>\n\tSymbols \u4e0e for&#8230;in \u8fed\u4ee3<br \/>\n<\/h2>\n<p>\n\tSymbols \u5728 for&#8230;in \u8fed\u4ee3\u4e2d\u4e0d\u53ef\u679a\u4e3e\u3002\u53e6\u5916\uff0cObject.getOwnPropertyNames() \u4e0d\u4f1a\u8fd4\u56de symbol \u5bf9\u8c61\u7684\u5c5e\u6027\uff0c\u4f46\u662f\u4f60\u80fd\u4f7f\u7528 Object.getOwnPropertySymbols() \u5f97\u5230\u5b83\u4eec\u3002\n<\/p>\n<pre class=\"brush:jscript;\">\r\nvar obj = {};\r\nobj[Symbol(\"a\")] = &quot;a&quot;;\r\nobj[Symbol.for(\"b\")] = &quot;b&quot;;\r\nobj[\"c\"] = &quot;c&quot;;\r\nobj.d = &quot;d&quot;;\r\nfor (var i in obj) {\r\n   console.log(i); \/\/ logs &quot;c&quot; and &quot;d&quot;\r\n}<\/pre>\n<h2>\n\tSymbols \u4e0e JSON.stringify()<br \/>\n<\/h2>\n<p>\n\t\u5f53\u4f7f\u7528 <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/JSON\/stringify\">JSON.strIngify()<\/a> \u65f6\u4ee5 symbol \u503c\u4f5c\u4e3a\u952e\u7684\u5c5e\u6027\u4f1a\u88ab\u5b8c\u5168\u5ffd\u7565\uff1a\n<\/p>\n<pre class=\"brush:jscript;\">\r\nJSON.stringify({[Symbol(\"foo\")]: &quot;foo&quot;});                 \r\n\/\/ &#039;{}&#039;<\/pre>\n<h2>\n\tSymbol \u5305\u88c5\u5668\u5bf9\u8c61\u4f5c\u4e3a\u5c5e\u6027\u7684\u952e<br \/>\n<\/h2>\n<p>\n\t\u5f53\u4e00\u4e2a Symbol \u5305\u88c5\u5668\u5bf9\u8c61\u4f5c\u4e3a\u4e00\u4e2a\u5c5e\u6027\u7684\u952e\u65f6\uff0c\u8fd9\u4e2a\u5bf9\u8c61\u5c06\u88ab\u5f3a\u5236\u8f6c\u6362\u4e3a\u5b83\u7684\u5305\u88c5\u8fc7\u7684 symbol \u503c\uff1a\n<\/p>\n<pre class=\"brush:jscript;\">\r\nvar sym = Symbol(&quot;foo&quot;);\r\nvar obj = {[sym]: 1};\r\nobj[sym];            \/\/ 1\r\nobj[Object(sym)];    \/\/ still 1<\/pre>\n<h2>\n\t\u53c2\u8003\u8d44\u6599<br \/>\n<\/h2>\n<ul>\n<li>\n\t\t<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/Symbol\">Glossary: Symbol data type<\/a>\n\t<\/li>\n<li>\n\t\t<a href=\"https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/JavaScript\/Reference\/Operators\/typeof\" title=\"typeof\u64cd\u4f5c\u7b26\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32,\u6307\u793a\u672a\u7ecf\u8ba1\u7b97\u7684\u64cd\u4f5c\u6570\u7684\u7c7b\u578b\u3002\"><code>typeof<\/code><\/a>\n\t<\/li>\n<li>\n\t\t<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Data_structures\">Data types and data structures<\/a>\n\t<\/li>\n<li>\n\t\t<a href=\"https:\/\/hacks.mozilla.org\/2015\/06\/es6-in-depth-symbols\/\">&quot;ES6 In Depth: Symbols&quot;\uff08\u6df1\u5165ES6 Symbols&nbsp;\uff09 on hacks.mozilla.org<\/a>\n\t<\/li>\n<\/ul>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=1656\">Symbols \u5faa\u73af\u8fed\u4ee3\u4e0e for&#8230;in \u8fed\u4ee3<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u524d\u9762\u8bf4\u4e86&nbsp;symbol \u662f\u4e00\u79cd\u6570\u636e\u7c7b\u578b\u3002\u65e2\u7136\u662f\u4e00\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u90a3\u4e48\u5b83\u5c31\u5e94\u8be5\u652f\u6301\u5faa\u73af\u8fed\u4ee3\u7b49\u8ba1\u7b97\u3002\u90a3\u4e48 s [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[1379,1106,1378],"class_list":["post-1656","post","type-post","status-publish","format-standard","hentry","category-html5","tag-es6","tag-javascript","tag-symbol"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1656"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1656\/revisions"}],"predecessor-version":[{"id":1657,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1656\/revisions\/1657"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}