{"id":4875,"date":"2016-03-15T12:00:12","date_gmt":"2016-03-15T04:00:12","guid":{"rendered":"https:\/\/sdeno.com\/?p=4875"},"modified":"2016-03-15T12:00:12","modified_gmt":"2016-03-15T04:00:12","slug":"javascript-%e4%b8%a5%e6%a0%bc%e6%a8%a1%e5%bc%8f%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=4875","title":{"rendered":"Javascript \u4e25\u683c\u6a21\u5f0f\u8be6\u89e3"},"content":{"rendered":"<p style=\"color: #111111;\">\u8bbe\u7acb&#8221;\u4e25\u683c\u6a21\u5f0f&#8221;\u7684\u76ee\u7684\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u4e2a\uff1a<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000- \u6d88\u9664Javascript\u8bed\u6cd5\u7684\u4e00\u4e9b\u4e0d\u5408\u7406\u3001\u4e0d\u4e25\u8c28\u4e4b\u5904\uff0c\u51cf\u5c11\u4e00\u4e9b\u602a\u5f02\u884c\u4e3a;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000- \u6d88\u9664\u4ee3\u7801\u8fd0\u884c\u7684\u4e00\u4e9b\u4e0d\u5b89\u5168\u4e4b\u5904\uff0c\u4fdd\u8bc1\u4ee3\u7801\u8fd0\u884c\u7684\u5b89\u5168\uff1b<\/p>\n<p style=\"color: #111111;\">\u3000\u3000- \u63d0\u9ad8\u7f16\u8bd1\u5668\u6548\u7387\uff0c\u589e\u52a0\u8fd0\u884c\u901f\u5ea6\uff1b<\/p>\n<p style=\"color: #111111;\">\u3000\u3000- \u4e3a\u672a\u6765\u65b0\u7248\u672c\u7684Javascript\u505a\u597d\u94fa\u57ab\u3002<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\">&#8220;\u4e25\u683c\u6a21\u5f0f&#8221;\u4f53\u73b0\u4e86Javascript\u66f4\u5408\u7406\u3001\u66f4\u5b89\u5168\u3001\u66f4\u4e25\u8c28\u7684\u53d1\u5c55\u65b9\u5411\uff0c\u5305\u62ecIE 10\u5728\u5185\u7684\u4e3b\u6d41\u6d4f\u89c8\u5668\uff0c\u90fd\u5df2\u7ecf<a style=\"color: #112233;\" href=\"http:\/\/kangax.github.com\/es5-compat-table\" target=\"_blank\">\u652f\u6301<\/a>\u5b83\uff0c\u8bb8\u591a\u5927\u9879\u76ee\u5df2\u7ecf\u5f00\u59cb\u5168\u9762\u62e5\u62b1\u5b83\u3002<\/p>\n<p style=\"color: #111111;\">\u53e6\u4e00\u65b9\u9762\uff0c\u540c\u6837\u7684\u4ee3\u7801\uff0c\u5728&#8221;\u4e25\u683c\u6a21\u5f0f&#8221;\u4e2d\uff0c\u53ef\u80fd\u4f1a\u6709\u4e0d\u4e00\u6837\u7684\u8fd0\u884c\u7ed3\u679c\uff1b\u4e00\u4e9b\u5728&#8221;\u6b63\u5e38\u6a21\u5f0f&#8221;\u4e0b\u53ef\u4ee5\u8fd0\u884c\u7684\u8bed\u53e5\uff0c\u5728&#8221;\u4e25\u683c\u6a21\u5f0f&#8221;\u4e0b\u5c06\u4e0d\u80fd\u8fd0\u884c\u3002\u638c\u63e1\u8fd9\u4e9b\u5185\u5bb9\uff0c\u6709\u52a9\u4e8e\u66f4\u7ec6\u81f4\u6df1\u5165\u5730\u7406\u89e3Javascript\uff0c\u8ba9\u4f60\u53d8\u6210\u4e00\u4e2a\u66f4\u597d\u7684\u7a0b\u5e8f\u5458\u3002<\/p>\n<p style=\"color: #111111;\">\u672c\u6587\u5c06\u5bf9&#8221;\u4e25\u683c\u6a21\u5f0f&#8221;\u505a\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">\u4e8c\u3001\u8fdb\u5165\u6807\u5fd7<\/strong><\/p>\n<p style=\"color: #111111;\">\u8fdb\u5165&#8221;\u4e25\u683c\u6a21\u5f0f&#8221;\u7684\u6807\u5fd7\uff0c\u662f\u4e0b\u9762\u8fd9\u884c\u8bed\u53e5\uff1a<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\">\u8001\u7248\u672c\u7684\u6d4f\u89c8\u5668\u4f1a\u628a\u5b83\u5f53\u4f5c\u4e00\u884c\u666e\u901a\u5b57\u7b26\u4e32\uff0c\u52a0\u4ee5\u5ffd\u7565\u3002<\/p>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">\u4e09\u3001\u5982\u4f55\u8c03\u7528<\/strong><\/p>\n<p style=\"color: #111111;\">&#8220;\u4e25\u683c\u6a21\u5f0f&#8221;\u6709\u4e24\u79cd\u8c03\u7528\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u573a\u5408\u3002<\/p>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">3.1 \u9488\u5bf9\u6574\u4e2a\u811a\u672c\u6587\u4ef6<\/strong><\/p>\n<p style=\"color: #111111;\">\u5c06&#8221;use strict&#8221;\u653e\u5728\u811a\u672c\u6587\u4ef6\u7684\u7b2c\u4e00\u884c\uff0c\u5219\u6574\u4e2a\u811a\u672c\u90fd\u5c06\u4ee5&#8221;\u4e25\u683c\u6a21\u5f0f&#8221;\u8fd0\u884c\u3002\u5982\u679c\u8fd9\u884c\u8bed\u53e5\u4e0d\u5728\u7b2c\u4e00\u884c\uff0c\u5219\u65e0\u6548\uff0c\u6574\u4e2a\u811a\u672c\u4ee5&#8221;\u6b63\u5e38\u6a21\u5f0f&#8221;\u8fd0\u884c\u3002\u5982\u679c\u4e0d\u540c\u6a21\u5f0f\u7684\u4ee3\u7801\u6587\u4ef6\u5408\u5e76\u6210\u4e00\u4e2a\u6587\u4ef6\uff0c\u8fd9\u4e00\u70b9\u9700\u8981\u7279\u522b\u6ce8\u610f\u3002<\/p>\n<p style=\"color: #111111;\">(\u4e25\u683c\u5730\u8bf4\uff0c\u53ea\u8981\u524d\u9762\u4e0d\u662f\u4ea7\u751f\u5b9e\u9645\u8fd0\u884c\u7ed3\u679c\u7684\u8bed\u53e5\uff0c&#8221;use strict&#8221;\u53ef\u4ee5\u4e0d\u5728\u7b2c\u4e00\u884c\uff0c\u6bd4\u5982\u76f4\u63a5\u8ddf\u5728\u4e00\u4e2a\u7a7a\u7684\u5206\u53f7\u540e\u9762\u3002)<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&lt;script&gt;<br \/>\n&#8220;use strict&#8221;;<br \/>\nconsole.log(&#8220;\u8fd9\u662f\u4e25\u683c\u6a21\u5f0f\u3002&#8221;);<br \/>\n&lt;\/script&gt;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000&lt;script&gt;<br \/>\nconsole.log(&#8220;\u8fd9\u662f\u6b63\u5e38\u6a21\u5f0f\u3002&#8221;);kly, it&#8217;s almost 2 years ago now. I can admit it now &#8211; I run it on my school&#8217;s network that has about 50 computers.<br \/>\n&lt;\/script&gt;<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\">\u4e0a\u9762\u7684\u4ee3\u7801\u8868\u793a\uff0c\u4e00\u4e2a\u7f51\u9875\u4e2d\u4f9d\u6b21\u6709\u4e24\u6bb5Javascript\u4ee3\u7801\u3002\u524d\u4e00\u4e2ascript\u6807\u7b7e\u662f\u4e25\u683c\u6a21\u5f0f\uff0c\u540e\u4e00\u4e2a\u4e0d\u662f\u3002<\/p>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">3.2 \u9488\u5bf9\u5355\u4e2a\u51fd\u6570<\/strong><\/p>\n<p style=\"color: #111111;\">\u5c06&#8221;use strict&#8221;\u653e\u5728\u51fd\u6570\u4f53\u7684\u7b2c\u4e00\u884c\uff0c\u5219\u6574\u4e2a\u51fd\u6570\u4ee5&#8221;\u4e25\u683c\u6a21\u5f0f&#8221;\u8fd0\u884c\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000function strict(){<br \/>\n&#8220;use strict&#8221;;<br \/>\nreturn &#8220;\u8fd9\u662f\u4e25\u683c\u6a21\u5f0f\u3002&#8221;;<br \/>\n}<\/p>\n<p style=\"color: #111111;\">\u3000\u3000function notStrict() {<br \/>\nreturn &#8220;\u8fd9\u662f\u6b63\u5e38\u6a21\u5f0f\u3002&#8221;;<br \/>\n}<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">3.3 \u811a\u672c\u6587\u4ef6\u7684\u53d8\u901a\u5199\u6cd5<\/strong><\/p>\n<p style=\"color: #111111;\">\u56e0\u4e3a\u7b2c\u4e00\u79cd\u8c03\u7528\u65b9\u6cd5\u4e0d\u5229\u4e8e\u6587\u4ef6\u5408\u5e76\uff0c\u6240\u4ee5\u66f4\u597d\u7684\u505a\u6cd5\u662f\uff0c\u501f\u7528\u7b2c\u4e8c\u79cd\u65b9\u6cd5\uff0c\u5c06\u6574\u4e2a\u811a\u672c\u6587\u4ef6\u653e\u5728\u4e00\u4e2a\u7acb\u5373\u6267\u884c\u7684\u533f\u540d\u51fd\u6570\u4e4b\u4e2d\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000(function (){<\/p>\n<p>&#8220;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000\/\/ some code here<\/p>\n<p>})();<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">\u56db\u3001\u8bed\u6cd5\u548c\u884c\u4e3a\u6539\u53d8<\/strong><\/p>\n<p style=\"color: #111111;\">\u4e25\u683c\u6a21\u5f0f\u5bf9Javascript\u7684\u8bed\u6cd5\u548c\u884c\u4e3a\uff0c\u90fd\u505a\u4e86\u4e00\u4e9b\u6539\u53d8\u3002<\/p>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">4.1 \u5168\u5c40\u53d8\u91cf\u663e\u5f0f\u58f0\u660e<\/strong><\/p>\n<p style=\"color: #111111;\">\u5728\u6b63\u5e38\u6a21\u5f0f\u4e2d\uff0c\u5982\u679c\u4e00\u4e2a\u53d8\u91cf\u6ca1\u6709\u58f0\u660e\u5c31\u8d4b\u503c\uff0c\u9ed8\u8ba4\u662f\u5168\u5c40\u53d8\u91cf\u3002\u4e25\u683c\u6a21\u5f0f\u7981\u6b62\u8fd9\u79cd\u7528\u6cd5\uff0c\u5168\u5c40\u53d8\u91cf\u5fc5\u987b\u663e\u5f0f\u58f0\u660e\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">&#8220;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000v = 1; \/\/ \u62a5\u9519\uff0cv\u672a\u58f0\u660e<\/p>\n<p style=\"color: #111111;\">\u3000\u3000for(i = 0; i &lt; 2; i++) { \/\/ \u62a5\u9519\uff0ci\u672a\u58f0\u660e<br \/>\n}<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\">\u56e0\u6b64\uff0c\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0c\u53d8\u91cf\u90fd\u5fc5\u987b\u5148\u7528var\u547d\u4ee4\u58f0\u660e\uff0c\u7136\u540e\u518d\u4f7f\u7528\u3002<\/p>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">4.2 \u9759\u6001\u7ed1\u5b9a<\/strong><\/p>\n<p style=\"color: #111111;\">Javascript\u8bed\u8a00\u7684\u4e00\u4e2a\u7279\u70b9\uff0c\u5c31\u662f\u5141\u8bb8&#8221;\u52a8\u6001\u7ed1\u5b9a&#8221;\uff0c\u5373\u67d0\u4e9b\u5c5e\u6027\u548c\u65b9\u6cd5\u5230\u5e95\u5c5e\u4e8e\u54ea\u4e00\u4e2a\u5bf9\u8c61\uff0c\u4e0d\u662f\u5728\u7f16\u8bd1\u65f6\u786e\u5b9a\u7684\uff0c\u800c\u662f\u5728\u8fd0\u884c\u65f6\uff08runtime\uff09\u786e\u5b9a\u7684\u3002<\/p>\n<p style=\"color: #111111;\">\u4e25\u683c\u6a21\u5f0f\u5bf9\u52a8\u6001\u7ed1\u5b9a\u505a\u4e86\u4e00\u4e9b\u9650\u5236\u3002\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ea\u5141\u8bb8\u9759\u6001\u7ed1\u5b9a\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5c5e\u6027\u548c\u65b9\u6cd5\u5230\u5e95\u5f52\u5c5e\u54ea\u4e2a\u5bf9\u8c61\uff0c\u5728\u7f16\u8bd1\u9636\u6bb5\u5c31\u786e\u5b9a\u3002\u8fd9\u6837\u505a\u6709\u5229\u4e8e\u7f16\u8bd1\u6548\u7387\u7684\u63d0\u9ad8\uff0c\u4e5f\u4f7f\u5f97\u4ee3\u7801\u66f4\u5bb9\u6613\u9605\u8bfb\uff0c\u66f4\u5c11\u51fa\u73b0\u610f\u5916\u3002<\/p>\n<p style=\"color: #111111;\">\u5177\u4f53\u6765\u8bf4\uff0c\u6d89\u53ca\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\u3002<\/p>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">\uff081\uff09\u7981\u6b62\u4f7f\u7528with\u8bed\u53e5<\/strong><\/p>\n<p style=\"color: #111111;\">\u56e0\u4e3awith\u8bed\u53e5\u65e0\u6cd5\u5728\u7f16\u8bd1\u65f6\u5c31\u786e\u5b9a\uff0c\u5c5e\u6027\u5230\u5e95\u5f52\u5c5e\u54ea\u4e2a\u5bf9\u8c61\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000var v = 1;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000with (o){ \/\/ \u8bed\u6cd5\u9519\u8bef<br \/>\nv = 2;<br \/>\n}<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">\uff082\uff09\u521b\u8bbeeval\u4f5c\u7528\u57df<\/strong><\/p>\n<p style=\"color: #111111;\">\u6b63\u5e38\u6a21\u5f0f\u4e0b\uff0cJavascript\u8bed\u8a00\u6709\u4e24\u79cd\u53d8\u91cf\u4f5c\u7528\u57df\uff08scope\uff09\uff1a\u5168\u5c40\u4f5c\u7528\u57df\u548c\u51fd\u6570\u4f5c\u7528\u57df\u3002\u4e25\u683c\u6a21\u5f0f\u521b\u8bbe\u4e86\u7b2c\u4e09\u79cd\u4f5c\u7528\u57df\uff1aeval\u4f5c\u7528\u57df\u3002<\/p>\n<p style=\"color: #111111;\">\u6b63\u5e38\u6a21\u5f0f\u4e0b\uff0ceval\u8bed\u53e5\u7684\u4f5c\u7528\u57df\uff0c\u53d6\u51b3\u4e8e\u5b83\u5904\u4e8e\u5168\u5c40\u4f5c\u7528\u57df\uff0c\u8fd8\u662f\u5904\u4e8e\u51fd\u6570\u4f5c\u7528\u57df\u3002\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0ceval\u8bed\u53e5\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u4f5c\u7528\u57df\uff0c\u4e0d\u518d\u80fd\u591f\u751f\u6210\u5168\u5c40\u53d8\u91cf\u4e86\uff0c\u5b83\u6240\u751f\u6210\u7684\u53d8\u91cf\u53ea\u80fd\u7528\u4e8eeval\u5185\u90e8\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000var x = 2;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000console.info(eval(&#8220;var x = 5; x&#8221;)); \/\/ 5<\/p>\n<p style=\"color: #111111;\">\u3000\u3000console.info(x); \/\/ 2<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">4.3 \u589e\u5f3a\u7684\u5b89\u5168\u63aa\u65bd<\/strong><\/p>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">\uff081\uff09\u7981\u6b62this\u5173\u952e\u5b57\u6307\u5411\u5168\u5c40\u5bf9\u8c61<\/strong><\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000function f(){<br \/>\nreturn !this;<br \/>\n}<br \/>\n\/\/ \u8fd4\u56defalse\uff0c\u56e0\u4e3a&#8221;this&#8221;\u6307\u5411\u5168\u5c40\u5bf9\u8c61\uff0c&#8221;!this&#8221;\u5c31\u662ffalse<\/p>\n<p style=\"color: #111111;\">\u3000\u3000function f(){<br \/>\n&#8220;use strict&#8221;;<br \/>\nreturn !this;<br \/>\n}<br \/>\n\/\/ \u8fd4\u56detrue\uff0c\u56e0\u4e3a\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0cthis\u7684\u503c\u4e3aundefined\uff0c\u6240\u4ee5&#8221;!this&#8221;\u4e3atrue\u3002<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\">\u56e0\u6b64\uff0c\u4f7f\u7528\u6784\u9020\u51fd\u6570\u65f6\uff0c\u5982\u679c\u5fd8\u4e86\u52a0new\uff0cthis\u4e0d\u518d\u6307\u5411\u5168\u5c40\u5bf9\u8c61\uff0c\u800c\u662f\u62a5\u9519\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000function f(){<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000this.a = 1;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000};<\/p>\n<p style=\"color: #111111;\">\u3000\u3000f();\/\/ \u62a5\u9519\uff0cthis\u672a\u5b9a\u4e49<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">\uff082\uff09\u7981\u6b62\u5728\u51fd\u6570\u5185\u90e8\u904d\u5386\u8c03\u7528\u6808<\/strong><\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000function f1(){<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000f1.caller; \/\/ \u62a5\u9519<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000f1.arguments; \/\/ \u62a5\u9519<\/p>\n<p style=\"color: #111111;\">\u3000\u3000}<\/p>\n<p style=\"color: #111111;\">\u3000\u3000f1();<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">4.4 \u7981\u6b62\u5220\u9664\u53d8\u91cf<\/strong><\/p>\n<p style=\"color: #111111;\">\u4e25\u683c\u6a21\u5f0f\u4e0b\u65e0\u6cd5\u5220\u9664\u53d8\u91cf\u3002\u53ea\u6709configurable\u8bbe\u7f6e\u4e3atrue\u7684\u5bf9\u8c61\u5c5e\u6027\uff0c\u624d\u80fd\u88ab\u5220\u9664\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000var x;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000delete x; \/\/ \u8bed\u6cd5\u9519\u8bef<\/p>\n<p style=\"color: #111111;\">\u3000\u3000var o = Object.create(null, {&#8216;x&#8217;: {<br \/>\nvalue: 1,<br \/>\nconfigurable: true<br \/>\n}});<\/p>\n<p style=\"color: #111111;\">\u3000\u3000delete o.x; \/\/ \u5220\u9664\u6210\u529f<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">4.5 \u663e\u5f0f\u62a5\u9519<\/strong><\/p>\n<p style=\"color: #111111;\">\u6b63\u5e38\u6a21\u5f0f\u4e0b\uff0c\u5bf9\u4e00\u4e2a\u5bf9\u8c61\u7684\u53ea\u8bfb\u5c5e\u6027\u8fdb\u884c\u8d4b\u503c\uff0c\u4e0d\u4f1a\u62a5\u9519\uff0c\u53ea\u4f1a\u9ed8\u9ed8\u5730\u5931\u8d25\u3002\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0c\u5c06\u62a5\u9519\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p>var o = {};<\/p>\n<p style=\"color: #111111;\">\u3000\u3000Object.defineProperty(o, &#8220;v&#8221;, { value: 1, writable: false });<\/p>\n<p style=\"color: #111111;\">\u3000\u3000o.v = 2; \/\/ \u62a5\u9519<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\">\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0c\u5bf9\u4e00\u4e2a\u4f7f\u7528getter\u65b9\u6cd5\u8bfb\u53d6\u7684\u5c5e\u6027\u8fdb\u884c\u8d4b\u503c\uff0c\u4f1a\u62a5\u9519\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p>var o = {<\/p>\n<p>get v() { return 1; }<\/p>\n<p style=\"color: #111111;\">\u3000\u3000};<\/p>\n<p style=\"color: #111111;\">\u3000\u3000o.v = 2; \/\/ \u62a5\u9519<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\">\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0c\u5bf9\u7981\u6b62\u6269\u5c55\u7684\u5bf9\u8c61\u6dfb\u52a0\u65b0\u5c5e\u6027\uff0c\u4f1a\u62a5\u9519\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000var o = {};<\/p>\n<p style=\"color: #111111;\">\u3000\u3000Object.preventExtensions(o);<\/p>\n<p style=\"color: #111111;\">\u3000\u3000o.v = 1; \/\/ \u62a5\u9519<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\">\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0c\u5220\u9664\u4e00\u4e2a\u4e0d\u53ef\u5220\u9664\u7684\u5c5e\u6027\uff0c\u4f1a\u62a5\u9519\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000delete Object.prototype; \/\/ \u62a5\u9519<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">4.6 \u91cd\u540d\u9519\u8bef<\/strong><\/p>\n<p style=\"color: #111111;\">\u4e25\u683c\u6a21\u5f0f\u65b0\u589e\u4e86\u4e00\u4e9b\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">\uff081\uff09\u5bf9\u8c61\u4e0d\u80fd\u6709\u91cd\u540d\u7684\u5c5e\u6027<\/strong><\/p>\n<p style=\"color: #111111;\">\u6b63\u5e38\u6a21\u5f0f\u4e0b\uff0c\u5982\u679c\u5bf9\u8c61\u6709\u591a\u4e2a\u91cd\u540d\u5c5e\u6027\uff0c\u6700\u540e\u8d4b\u503c\u7684\u90a3\u4e2a\u5c5e\u6027\u4f1a\u8986\u76d6\u524d\u9762\u7684\u503c\u3002\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0c\u8fd9\u5c5e\u4e8e\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000var o = {<br \/>\np: 1,<br \/>\np: 2<br \/>\n}; \/\/ \u8bed\u6cd5\u9519\u8bef<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\">\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">\uff082\uff09\u51fd\u6570\u4e0d\u80fd\u6709\u91cd\u540d\u7684\u53c2\u6570<\/strong><\/p>\n<p style=\"color: #111111;\">\u6b63\u5e38\u6a21\u5f0f\u4e0b\uff0c\u5982\u679c\u51fd\u6570\u6709\u591a\u4e2a\u91cd\u540d\u7684\u53c2\u6570\uff0c\u53ef\u4ee5\u7528arguments[i]\u8bfb\u53d6\u3002\u4e25\u683c\u6a21\u5f0f\u4e0b\uff0c\u8fd9\u5c5e\u4e8e\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000function f(a, a, b) { \/\/ \u8bed\u6cd5\u9519\u8bef<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000return ;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000}<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">4.7 \u7981\u6b62\u516b\u8fdb\u5236\u8868\u793a\u6cd5<\/strong><\/p>\n<p style=\"color: #111111;\">\u6b63\u5e38\u6a21\u5f0f\u4e0b\uff0c\u6574\u6570\u7684\u7b2c\u4e00\u4f4d\u5982\u679c\u662f0\uff0c\u8868\u793a\u8fd9\u662f\u516b\u8fdb\u5236\u6570\uff0c\u6bd4\u59820100\u7b49\u4e8e\u5341\u8fdb\u5236\u768464\u3002\u4e25\u683c\u6a21\u5f0f\u7981\u6b62\u8fd9\u79cd\u8868\u793a\u6cd5\uff0c\u6574\u6570\u7b2c\u4e00\u4f4d\u4e3a0\uff0c\u5c06\u62a5\u9519\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000var n = 0100; \/\/ \u8bed\u6cd5\u9519\u8bef<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">4.8 arguments\u5bf9\u8c61\u7684\u9650\u5236<\/strong><\/p>\n<p style=\"color: #111111;\">arguments\u662f\u51fd\u6570\u7684\u53c2\u6570\u5bf9\u8c61\uff0c\u4e25\u683c\u6a21\u5f0f\u5bf9\u5b83\u7684\u4f7f\u7528\u505a\u4e86\u9650\u5236\u3002<\/p>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">\uff081\uff09\u4e0d\u5141\u8bb8\u5bf9arguments\u8d4b\u503c<\/strong><\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000arguments++; \/\/ \u8bed\u6cd5\u9519\u8bef<\/p>\n<p style=\"color: #111111;\">\u3000\u3000var obj = { set p(arguments) { } }; \/\/ \u8bed\u6cd5\u9519\u8bef<\/p>\n<p style=\"color: #111111;\">\u3000\u3000try { } catch (arguments) { } \/\/ \u8bed\u6cd5\u9519\u8bef<\/p>\n<p style=\"color: #111111;\">\u3000\u3000function arguments() { } \/\/ \u8bed\u6cd5\u9519\u8bef<\/p>\n<p style=\"color: #111111;\">\u3000\u3000var f = new Function(&#8220;arguments&#8221;, &#8220;&#8216;use strict&#8217;; return 17;&#8221;); \/\/ \u8bed\u6cd5\u9519\u8bef<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">\uff082\uff09arguments\u4e0d\u518d\u8ffd\u8e2a\u53c2\u6570\u7684\u53d8\u5316<\/strong><\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000function f(a) {<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000a = 2;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000return [a, arguments[0]];<\/p>\n<p style=\"color: #111111;\">\u3000\u3000}<\/p>\n<p style=\"color: #111111;\">\u3000\u3000f(1); \/\/ \u6b63\u5e38\u6a21\u5f0f\u4e3a[2,2]<\/p>\n<p style=\"color: #111111;\">\u3000\u3000function f(a) {<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000a = 2;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000return [a, arguments[0]];<\/p>\n<p style=\"color: #111111;\">\u3000\u3000}<\/p>\n<p style=\"color: #111111;\">\u3000\u3000f(1); \/\/ \u4e25\u683c\u6a21\u5f0f\u4e3a[2,1]<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">\uff083\uff09\u7981\u6b62\u4f7f\u7528arguments.callee<\/strong><\/p>\n<p style=\"color: #111111;\">\u8fd9\u610f\u5473\u7740\uff0c\u4f60\u65e0\u6cd5\u5728\u533f\u540d\u51fd\u6570\u5185\u90e8\u8c03\u7528\u81ea\u8eab\u4e86\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000var f = function() { return arguments.callee; };<\/p>\n<p style=\"color: #111111;\">\u3000\u3000f(); \/\/ \u62a5\u9519<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">4.9 \u51fd\u6570\u5fc5\u987b\u58f0\u660e\u5728\u9876\u5c42<\/strong><\/p>\n<p style=\"color: #111111;\">\u5c06\u6765Javascript\u7684\u65b0\u7248\u672c\u4f1a\u5f15\u5165&#8221;\u5757\u7ea7\u4f5c\u7528\u57df&#8221;\u3002\u4e3a\u4e86\u4e0e\u65b0\u7248\u672c\u63a5\u8f68\uff0c\u4e25\u683c\u6a21\u5f0f\u53ea\u5141\u8bb8\u5728\u5168\u5c40\u4f5c\u7528\u57df\u6216\u51fd\u6570\u4f5c\u7528\u57df\u7684\u9876\u5c42\u58f0\u660e\u51fd\u6570\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e0d\u5141\u8bb8\u5728\u975e\u51fd\u6570\u7684\u4ee3\u7801\u5757\u5185\u58f0\u660e\u51fd\u6570\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000if (true) {<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000function f() { } \/\/ \u8bed\u6cd5\u9519\u8bef<\/p>\n<p style=\"color: #111111;\">\u3000\u3000}<\/p>\n<p style=\"color: #111111;\">\u3000\u3000for (var i = 0; i &lt; 5; i++) {<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000function f2() { } \/\/ \u8bed\u6cd5\u9519\u8bef<\/p>\n<p style=\"color: #111111;\">\u3000\u3000}<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\"><strong style=\"font-weight: 800;\">4.10 \u4fdd\u7559\u5b57<\/strong><\/p>\n<p style=\"color: #111111;\">\u4e3a\u4e86\u5411\u5c06\u6765Javascript\u7684\u65b0\u7248\u672c\u8fc7\u6e21\uff0c\u4e25\u683c\u6a21\u5f0f\u65b0\u589e\u4e86\u4e00\u4e9b\u4fdd\u7559\u5b57\uff1aimplements, interface, let, package, private, protected, public, static, yield\u3002<\/p>\n<p style=\"color: #111111;\">\u4f7f\u7528\u8fd9\u4e9b\u8bcd\u4f5c\u4e3a\u53d8\u91cf\u540d\u5c06\u4f1a\u62a5\u9519\u3002<\/p>\n<blockquote style=\"color: #111111;\">\n<p style=\"color: #111111;\">\u3000\u3000function package(protected) { \/\/ \u8bed\u6cd5\u9519\u8bef<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000&#8221;use strict&#8221;;<\/p>\n<p style=\"color: #111111;\">\u3000\u3000\u3000\u3000var implements; \/\/ \u8bed\u6cd5\u9519\u8bef<\/p>\n<p style=\"color: #111111;\">\u3000\u3000}<\/p>\n<\/blockquote>\n<p style=\"color: #111111;\">\u6b64\u5916\uff0cECMAscript\u7b2c\u4e94\u7248\u672c\u8eab\u8fd8\u89c4\u5b9a\u4e86\u53e6\u4e00\u4e9b\u4fdd\u7559\u5b57\uff08class, enum, export, extends, import, super\uff09\uff0c\u4ee5\u53ca\u5404\u5927\u6d4f\u89c8\u5668\u81ea\u884c\u589e\u52a0\u7684const\u4fdd\u7559\u5b57\uff0c\u4e5f\u662f\u4e0d\u80fd\u4f5c\u4e3a\u53d8\u91cf\u540d\u7684\u3002<\/p>\n<p style=\"color: #111111;\"><a href=\"http:\/\/www.ruanyifeng.com\/blog\/2013\/01\/javascript_strict_mode.html\" target=\"_blank\">http:\/\/www.ruanyifeng.com\/blog\/2013\/01\/javascript_strict_mode.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bbe\u7acb&#8221;\u4e25\u683c\u6a21\u5f0f&#8221;\u7684\u76ee\u7684\uff0c\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u4e2a\uff1a \u3000\u3000- \u6d88\u9664Javascript\u8bed\u6cd5\u7684\u4e00\u4e9b\u4e0d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-4875","post","type-post","status-publish","format-standard","hentry","category-11"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/4875","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4875"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/4875\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}