{"id":161,"date":"2015-03-14T19:38:41","date_gmt":"2015-03-14T11:38:41","guid":{"rendered":"http:\/\/miku.host.smartgslb.com\/?p=161"},"modified":"2015-03-14T19:38:41","modified_gmt":"2015-03-14T11:38:41","slug":"js%e5%b8%a6%e4%bd%a0%e9%a2%a0%e8%a6%86%e4%b8%96%e7%95%8c%e8%a7%82","status":"publish","type":"post","link":"https:\/\/sora.sound.moe\/?p=161","title":{"rendered":"js\u5e26\u4f60\u98a0\u8986\u4e16\u754c\u89c2"},"content":{"rendered":"<p>(![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]<\/p>\n<p>\u8fd9\u79cdJavaScript\u4ee3\u7801\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u5462\uff0c\u4e0d\u59a8\u6765\u89e3\u6790\u4e00\u4e0b\u3002<\/p>\n<p>http:\/\/stackoverflow.com\/questions\/4170978\/explain-why-this-works<\/p>\n<p><!--more--><\/p>\n<pre class=\"lang:js decode:true \">alert((![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]);<\/pre>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u7684\u8fd0\u884c\u7ed3\u679c\u662falert(&#8216;fail&#8217;); \u00a0\u6709\u7684\u4eba\u53ef\u80fd\u770b\u5230\u8fd9\u5c31\u8981\u8bf4js\u98a0\u8986\u4e16\u754c\u89c2\u4e86\uff0c\u5176\u5b9e\u4ed4\u7ec6\u770b\u770b\u4e5f\u4e0d\u662f\u90a3\u4e48\u626f\u6de1\uff0c\u4e3b\u8981\u5c31\u662f\u7075\u6d3b\u7684\u7c7b\u578b\u8f6c\u6362\u548c+\u3001!\u8fd0\u7b97\u7b26\u7684\u4e00\u4e9b\u8fd0\u7528\u3002<\/p>\n<p>\u6765\u5206\u6b65\u89e3\u6790<\/p>\n<pre class=\"lang:js decode:true\">(![]+[])[+[]]; \/\/ 'f'<\/pre>\n<p>OAO\u8fd9\u662f\u600e\u4e48\u88ab\u89e3\u6790\u4e3af\u7684\uff1f\uff01<\/p>\n<p>\u4e0d\u8981\u6025\uff01\u6765\u770b<\/p>\n<pre class=\"lang:js decode:true \">![] \/\/ false<\/pre>\n<p>[]\u4ea7\u751f\u4e00\u4e2a\u7a7a\u6570\u7ec4\uff0c!\u8fd0\u7b97\u7b26\u5bf9\u4e8e\u4efb\u4f55<strong>\u4e0efalse\u4e0d\u4e25\u683c\u76f8\u7b49<\/strong>\u7684\u503c\uff0c\u90fd\u8fd4\u56defalse\u3002\u5728!\u8fd0\u7b97\u7b26\u540e\u7684\u5c06\u4f1a\u88ab\u9690\u5f0f\u8f6c\u6362\u4e3aboolean\u7c7b\u578b\u3002<\/p>\n<pre class=\"lang:js decode:true\">![]; \/\/ false, \u7a7a\u6570\u7ec4\u4e3a\u771f\n!{}; \/\/ false, \u7a7a\u5bf9\u8c61\u4e3a\u771f\n!0;  \/\/ true, 0\u88ab\u8f6c\u6362\u4e3afalse\n!NaN;  \/\/ true, NaN\u88ab\u8f6c\u6362\u4e3afalse<\/pre>\n<p>\u7136\u540e\uff0c\u6211\u4eec\u505a\u4e86\u8fd9\u6837\u7684\u64cd\u4f5c\uff1a<\/p>\n<pre class=\"lang:js decode:true\">false + [] \/\/ \"false\"<\/pre>\n<p>\u54a6\uff0c\u600e\u4e48\u53d8\u6210\u5b57\u7b26\u4e32\u4e86\u5462\u3002\u539f\u56e0\u5728\u4e8e[]\u8fd9\u4e2a\u7a7a\u6570\u7ec4\u5728\u7ecf\u8fc7\u8f6c\u6362\u540e\u53d8\u6210\u4e86\u7a7a\u5b57\u7b26\u4e32\uff0c\u4f7f\u7528+\u8fd0\u7b97\u7b26\u548cfalse\u8fde\u63a5\u65f6\uff0cfalse\u5c06\u4f1a\u88ab\u8f6c\u6362\u4e3a&#8221;false&#8221;\u3002<\/p>\n<pre class=\"lang:js decode:true \">false.toString() \/\/\"false\"\n[].toString()  \/\/\"\"<\/pre>\n<p>\u8fd9\u91cc\u63d0\u4e00\u4e0b\uff0c+\u8fd0\u7b97\u7b26\u7684\u4e00\u4e9b\u7528\u6cd5\u3002+\u8fd0\u7b97\u7b26\u53ef\u4ee5\u505a\u52a0\u6cd5\uff0c\u4e5f\u53ef\u4ee5\u505a\u5b57\u7b26\u4e32\u8fde\u63a5\u7684\u5de5\u4f5c\u3002<\/p>\n<p>\u5f53\u5de6\u53f3\u4e24\u4e2a\u64cd\u4f5c\u6570\u90fd\u662f\u6570\u5b57\u6216\u8005\u5b57\u7b26\u4e32\u65f6\uff0c\u7ed3\u679c\u663e\u800c\u6613\u89c1\u3002<\/p>\n<p>\u5982\u679c\u4e24\u4e2a\u64cd\u4f5c\u6570\u4e2d\u6709\u4e00\u4e2a\u662f\u5bf9\u8c61\uff0c\u5c31\u4f1a\u8c03\u7528\u5176\u7684toString()\u65b9\u6cd5\uff0c\u6216valueOf()\u65b9\u6cd5\uff0c\u5c06\u5176\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u5c06\u53e6\u4e00\u4e2a\u64cd\u4f5c\u6570\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\uff0c\u8fdb\u884c\u5b57\u7b26\u4e32\u8fde\u63a5\u3002\u5982\u679c\u4e24\u4e2a\u5b57\u7b26\u4e32\u90fd\u4e0d\u662fstring-like\uff0c\u90a3\u4e48\u5219\u8fdb\u884c\u52a0\u6cd5\u3002<\/p>\n<p>\u53e6\u5916\uff0c+\u8fd0\u7b97\u7b26\u8fd8\u53ef\u4ee5\u505a\u7c7b\u578b\u8f6c\u6362\u7684\u5de5\u4f5c\u3002<\/p>\n<pre class=\"lang:js decode:true \">+ '1' \/\/ 1\n+ []  \/\/ 0 \u8fd9\u91cc[]\u662f\u4e00\u4e2a\u7a7a\u503c\uff0c\u6240\u4ee5\u8f6c\u6362\u6210\u6570\u5b57\u7684\u65f6\u5019\u662f0 \u5982\u679c\u8f6c\u6362\u4e3aboolean\u5c31\u662ffalse<\/pre>\n<p>\u90a3\u4e48\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u7684\u6700\u540e\u4e00\u6b65\u4e5f\u5c31\u51fa\u6765\u4e86\u3002\u5b8c\u6574\u7684\u6d41\u7a0b\u5982\u4e0b\u3002<\/p>\n<pre class=\"lang:js decode:true \">(![]+[])[+[]];\n(false+[])[+[]];\n(false+'')[+[]];\n(false+'')[0];\n('false')[0];  \/\/ \"f\"<\/pre>\n<p>&nbsp;<\/p>\n<p>\u6ce8\u610f\uff0c\u7528[]\u6765\u8bbf\u95ee\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\uff0c\u662fECMAScript5\u7684\u6807\u51c6\uff0c\u5728ES3\u4e2d\u6709charAt()\u51fd\u6570\u3002<\/p>\n<p>\u5176\u4ed6\u7684\u4e5f\u5c31\u5927\u540c\u5c0f\u5f02\u4e86\u3002<\/p>\n<p>\u53c2\u8003\uff1a<\/p>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Guide\/Expressions_and_Operators\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Guide\/Expressions_and_Operators<\/a><\/p>\n<p>\u300aJacaScript\u6743\u5a01\u6307\u5357\u300b\u7b2c70~71\u9875<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[] &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/sora.sound.moe\/?p=161\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cjs\u5e26\u4f60\u98a0\u8986\u4e16\u754c\u89c2\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[13],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"twentyseventeen-featured-image":false,"twentyseventeen-thumbnail-avatar":false},"uagb_author_info":{"display_name":"Sora","author_link":"https:\/\/sora.sound.moe\/?author=1"},"uagb_comment_info":0,"uagb_excerpt":"(![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]&hellip;","_links":{"self":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/posts\/161"}],"collection":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=161"}],"version-history":[{"count":0,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=\/wp\/v2\/posts\/161\/revisions"}],"wp:attachment":[{"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sora.sound.moe\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}