{"id":58,"date":"2011-10-14T19:08:03","date_gmt":"2011-10-14T11:08:03","guid":{"rendered":"https:\/\/blog.indeex.club\/?p=58"},"modified":"2020-06-20T22:37:04","modified_gmt":"2020-06-20T14:37:04","slug":"ecmascript-5-%e5%87%bd%e6%95%b0%e5%9f%ba%e7%a1%80","status":"publish","type":"post","link":"https:\/\/blog.indeex.club\/index.php\/2011\/10\/14\/ecmascript-5-%e5%87%bd%e6%95%b0%e5%9f%ba%e7%a1%80\/","title":{"rendered":"ECMAScript 5 \u51fd\u6570\u57fa\u7840"},"content":{"rendered":"<p><span style=\"font-family: 'comic sans ms', sans-serif;\"><strong>1.1\u51fd\u6570\u58f0\u660e<\/strong><\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u51fd\u6570\u5c31\u662f\u4e00\u6bb5\u53ef\u4ee5\u53cd\u590d\u8c03\u7528\u7684\u4ee3\u7801\u5757\u3002\u51fd\u6570\u58f0\u660e\u7531\u4e09\u90e8\u5206\u7ec4\u6210\uff1a\u51fd\u6570\u540d\uff0c\u51fd\u6570\u53c2\u6570\uff0c\u51fd\u6570\u4f53\u3002\u6574\u4f53\u7684\u6784\u9020\u662ffunction\u547d\u4ee4\u540e\u9762\u662f\u51fd\u6570\u540d\uff0c\u51fd\u6570\u540d\u540e\u9762\u662f\u4e00\u5bf9\u5706\u62ec\u53f7\uff0c\u91cc\u9762\u662f\u4f20\u5165\u51fd\u6570\u7684\u53c2\u6570\u3002\u51fd\u6570\u4f53\u653e\u5728\u5927\u62ec\u53f7\u91cc\u9762\u3002\u5f53\u51fd\u6570\u4f53\u6ca1\u6709\u4f7f\u7528return\u5173\u952e\u5b57\u8fd4\u56de\u51fd\u6570\u65f6\uff0c\u51fd\u6570\u8c03\u7528\u65f6\u8fd4\u56de\u9ed8\u8ba4\u7684undefined\uff1b\u5982\u679c\u6709\u4f7f\u7528return\u8bed\u53e5\uff0c\u5219\u8fd4\u56de\u6307\u5b9a\u5185\u5bb9\u3002\u51fd\u6570\u6700\u540e\u4e0d\u7528\u52a0\u4e0a\u5192\u53f7\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function fun(){}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(fun)\u00a0\u00a0 \/\/ &#8216;undefined&#8217;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function rascal(){<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">return &#8216;rascal&#8217;;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(rascal)\u00a0\u00a0\u00a0 \/\/ &#8216;rascal&#8217;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u51fd\u6570\u58f0\u660e\u662f\u5728\u9884\u6267\u884c\u671f\u6267\u884c\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u51fd\u6570\u58f0\u660e\u662f\u5728\u6d4f\u89c8\u5668\u51c6\u5907\u89e3\u6790\u5e76\u6267\u884c\u811a\u672c\u4ee3\u7801\u7684\u65f6\u5019\u6267\u884c\u7684\u3002\u6240\u4ee5\uff0c\u5f53\u53bb\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\u58f0\u660e\u65f6\uff0c\u53ef\u4ee5\u5728\u5176\u524d\u9762\u8c03\u7528\u5e76\u4e14\u4e0d\u4f1a\u62a5\u9519\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(rascal)\u00a0\u00a0 \/\/ &#8216;rascal&#8217;2<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function rascal(){<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">return &#8216;rascal&#8217;;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u5176\u5b9e\u8fd9\u6bb5\u4ee3\u7801\u6ca1\u6709\u62a5\u9519\u7684\u539f\u56e0\u8fd8\u6709\u4e00\u4e2a\uff0c\u5c31\u662f\u4e0e\u53d8\u91cf\u58f0\u660e\u63d0\u5347\u4e00\u6837\uff0c\u51fd\u6570\u540d\u4e5f\u4f1a\u53d1\u751f\u63d0\u5347\u3002\u51fd\u6570\u540d\u63d0\u5347\u4f1a\u5728\u4e0b\u9762\u5c0f\u8282\u8c08\u5230\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\"><strong>1.2<\/strong><strong>\uff1a\u51fd\u6570\u8868\u8fbe\u5f0f<\/strong><\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u51fd\u6570\u8868\u8fbe\u5f0f\u662f\u628a\u4e00\u4e2a\u533f\u540d\u51fd\u6570\u8d4b\u7ed9\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\u3002\u8fd9\u4e2a\u533f\u540d\u51fd\u6570\u53c8\u79f0\u4e3a\u51fd\u6570\u8868\u8fbe\u5f0f\uff0c\u56e0\u4e3a\u8d4b\u503c\u8bed\u53e5\u7684\u7b49\u53f7\u53f3\u4fa7\u53ea\u80fd\u653e\u8868\u8fbe\u5f0f\u3002\u51fd\u6570\u8868\u8fbe\u5f0f\u672b\u5c3e\u9700\u8981\u52a0\u4e0a\u5206\u53f7\uff0c\u8868\u793a\u8bed\u53e5\u7ed3\u675f\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var fun = function {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\/\/\u51fd\u6570\u4f53<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">};<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u51fd\u6570\u8868\u8fbe\u5f0f\u4e0e\u51fd\u6570\u58f0\u660e\u4e0d\u540c\u7684\u662f\uff0c\u51fd\u6570\u8868\u8fbe\u5f0f\u662f\u6d4f\u89c8\u5668\u89e3\u6790\u5e76\u6267\u884c\u5230\u90a3\u4e00\u884c\u624d\u4f1a\u6709\u5b9a\u4e49\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e0d\u80fd\u5728\u51fd\u6570\u5b9a\u4e49\u4e4b\u524d\u8c03\u7528\u51fd\u6570\u3002\u51fd\u6570\u8868\u8fbe\u5f0f\u5e76\u4e0d\u50cf\u51fd\u6570\u58f0\u660e\u4e00\u6837\u6709\u51fd\u6570\u540d\u7684\u63d0\u5347\u3002\u5982\u679c\u91c7\u7528\u8d4b\u503c\u8bed\u53e5\u5b9a\u4e49\u51fd\u6570\u5e76\u4e14\u5728\u58f0\u660e\u51fd\u6570\u524d\u8c03\u7528\u51fd\u6570\uff0cJavaScript\u5c31\u4f1a\u62a5\u9519\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">fun();<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var fun = function {};<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\/\/ TypeError: fun is not a function<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4e0a\u9762\u7684\u4ee3\u7801\u7b49\u540c\u4e8e\u4e0b\u9762\u7684\u5f62\u5f0f\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var fun;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(fun);\u00a0\u00a0 \/\/ TypeError: fun is not a function<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">fun = function {};<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4e0a\u9762\u4ee3\u7801\u7b2c\u4e8c\u884c\uff0c\u8c03\u7528fun\u7684\u65f6\u5019\uff0cfun\u53ea\u662f\u88ab\u58f0\u660e\u4e86\uff0c\u8fd8\u6ca1\u6709\u88ab\u8d4b\u503c\uff0c\u7b49\u4e8eundefined\uff0c\u6240\u4ee5\u4f1a\u62a5\u9519\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\"><strong>1.3<\/strong><strong>\uff1a\u547d\u540d\u51fd\u6570\u7684\u51fd\u6570\u8868\u8fbe\u5f0f<\/strong><\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u91c7\u7528\u51fd\u6570\u8868\u8fbe\u5f0f\u58f0\u660e\u51fd\u6570\u65f6\uff0cfunction\u547d\u4ee4\u540e\u9762\u4e0d\u5e26\u6709\u51fd\u6570\u540d\u3002\u5982\u679c\u52a0\u4e0a\u51fd\u6570\u540d\uff0c\u8be5\u51fd\u6570\u540d\u53ea\u5728\u51fd\u6570\u4f53\u5185\u90e8\u6709\u6548\uff0c\u5728\u51fd\u6570\u4f53\u5916\u90e8\u65e0\u6548\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var fun = function boy(){<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(typeof (boy));<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">};<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(boy);\u00a0\u00a0\u00a0\u00a0 \/\/ ReferenceError: boy is not defined<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">fun();\u00a0\u00a0\u00a0\u00a0 \/\/ function<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4e0a\u9762\u4ee3\u7801\u5728\u51fd\u6570\u8868\u8fbe\u5f0f\u4e2d\uff0c\u52a0\u5165\u4e86\u51fd\u6570\u540dboy\u3002\u8fd9\u4e2aboy\u53ea\u5728\u51fd\u6570\u4f53\u5185\u90e8\u53ef\u7528\uff0c\u6307\u4ee3\u51fd\u6570\u8868\u8fbe\u5f0f\u672c\u8eab\uff0c\u5176\u4ed6\u5730\u65b9\u90fd\u4e0d\u53ef\u7528\u3002\u8fd9\u79cd\u5199\u6cd5\u7684\u7528\u5904\u6709\u4e24\u4e2a\uff0c\u4e00\u662f\u53ef\u4ee5\u5728\u51fd\u6570\u4f53\u5185\u90e8\u8c03\u7528\u81ea\u8eab\uff0c\u4e8c\u662f\u65b9\u4fbf\u9664\u9519\uff08\u9664\u9519\u5de5\u5177\u663e\u793a\u51fd\u6570\u8c03\u7528\u6808\u65f6\uff0c\u5c06\u663e\u793a\u51fd\u6570\u540d\uff0c\u800c\u4e0d\u518d\u663e\u793a\u8fd9\u91cc\u662f\u4e00\u4e2a\u533f\u540d\u51fd\u6570\uff09\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\"><strong>1.4<\/strong><strong>\uff1a\u51fd\u6570\u7684\u91cd\u590d\u58f0\u660e<\/strong><\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u5982\u679c\u540c\u4e00\u4e2a\u51fd\u6570\u88ab\u591a\u6b21\u58f0\u660e\uff0c\u540e\u9762\u7684\u58f0\u660e\u5c31\u4f1a\u8986\u76d6\u524d\u9762\u7684\u58f0\u660e\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function fun() {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(1);<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">fun(); \/\/25<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function fun() {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(2);<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">fun(); \/\/2<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4e0a\u9762\u4ee3\u7801\u4e2d\uff0c\u540e\u4e00\u6b21\u7684\u51fd\u6570\u58f0\u660e\u8986\u76d6\u4e86\u524d\u9762\u4e00\u6b21\u3002\u800c\u4e14\uff0c\u7531\u4e8e\u51fd\u6570\u540d\u7684\u63d0\u5347\uff0c\u524d\u4e00\u6b21\u58f0\u660e\u5728\u4efb\u4f55\u65f6\u5019\u90fd\u662f\u65e0\u6548\u7684\u3002JavaScript\u5f15\u64ce\u5c06\u51fd\u6570\u540d\u89c6\u540c\u53d8\u91cf\u540d\uff0c\u6240\u4ee5\u91c7\u7528\u51fd\u6570\u58f0\u660e\u7684\u65b9\u5f0f\u58f0\u660e\u51fd\u6570\u65f6\uff0c\u6574\u4e2a\u51fd\u6570\u4f1a\u50cf\u53d8\u91cf\u58f0\u660e\u4e00\u6837\uff0c\u88ab\u63d0\u5347\u5230\u4ee3\u7801\u5934\u90e8\u3002\u8868\u9762\u4e0a\uff0c\u4e0a\u9762\u4ee3\u7801\u597d\u50cf\u5728\u58f0\u660e\u4e4b\u524d\u5c31\u8c03\u7528\u4e86\u51fd\u6570fun\u3002\u4f46\u662f\u5b9e\u9645\u4e0a\uff0c\u7531\u4e8e\u201c\u53d8\u91cf\u63d0\u5347\u201d\uff0c\u51fd\u6570fun\u88ab\u63d0\u5347\u5230\u4e86\u4ee3\u7801\u5934\u90e8\uff0c\u4e5f\u5c31\u662f\u5728\u8c03\u7528\u4e4b\u524d\u5df2\u7ecf\u58f0\u660e\u4e86\u3002\u518d\u770b\u4e00\u4e2a\u5178\u578b\u7684\u4f8b\u5b50\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">if (true) {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function fun() {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">return 1;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">} else {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function fun() {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">return 2;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(fun()) \/\/2<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u8fd9\u4e2a\u4f8b\u5b50\u5341\u5206\u5178\u578b\uff0c\u8c03\u7528fun\u51fd\u6570\u4e4b\u540e\u8fd4\u56de\u7684\u662f2\uff0c\u800c\u4e0d\u662f1\u3002\u5728\u6761\u4ef6\u8bed\u53e5\u4e2d\u58f0\u660e\u51fd\u6570\u4f1a\u5728\u4e0b\u9762\u8bf4\u5230\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\"><strong>1.5<\/strong><strong>\uff1a\u4e0d\u80fd\u5728\u6761\u4ef6\u8bed\u53e5\u4e2d\u58f0\u660e\u51fd\u6570<\/strong><\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u5b98\u65b9\u539f\u6587\u6709\u90a3\u4e48\u4e00\u53e5\u8bdd\uff08\u672c\u4eba\u7ffb\u8bd1\uff09\uff1a\u5728\u6761\u4ef6\u8bed\u53e5\u4e2d\u58f0\u660e\u51fd\u6570\u662f\u975e\u6807\u51c6\u7ed3\u6784\u7684\u7279\u5f81\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728if\u4ee3\u7801\u5757\u58f0\u660e\u4e86\u51fd\u6570\uff0c\u6309\u7167\u8bed\u8a00\u89c4\u8303\uff0c\u8fd9\u662f\u4e0d\u5408\u6cd5\u7684\u3002\u4f46\u662f\uff0c\u5b9e\u9645\u60c5\u51b5\u662f\u5404\u5bb6\u6d4f\u89c8\u5668\u5f80\u5f80\u5e76\u4e0d\u62a5\u9519\uff0c\u80fd\u591f\u8fd0\u884c\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u7531\u4e8e\u5b58\u5728\u51fd\u6570\u540d\u7684\u63d0\u5347\uff0c\u6240\u4ee5\u5728\u6761\u4ef6\u8bed\u53e5\u4e2d\u58f0\u660e\u51fd\u6570\uff0c\u53ef\u80fd\u662f\u65e0\u6548\u7684\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">if (false) {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function f {}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(f);\u00a0\u00a0 \/\/undefined<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4e0a\u9762\u4ee3\u7801\u7684\u539f\u59cb\u610f\u56fe\u662f\u4e0d\u58f0\u660e\u51fd\u6570f\uff0c\u4f46\u662f\u7531\u4e8ef\u7684\u63d0\u5347\uff0c\u5bfc\u81f4if\u8bed\u53e5\u65e0\u6548\uff0c\u6240\u4ee5\u4e0a\u9762\u7684\u4ee3\u7801\u4e0d\u4f1a\u62a5\u9519\u3002\u8981\u8fbe\u5230\u5728\u6761\u4ef6\u8bed\u53e5\u4e2d\u5b9a\u4e49\u51fd\u6570\u7684\u76ee\u7684\uff0c\u53ea\u6709\u4f7f\u7528\u51fd\u6570\u8868\u8fbe\u5f0f\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">if (false) {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var f = function\u00a0 {};<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(f) \/\/Uncaught TypeError: f is not a function<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\"><strong>2.1<\/strong><strong>\uff1aname\u5c5e\u6027<\/strong><\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">name\u5c5e\u6027\u8fd4\u56de\u7d27\u8ddf\u5728function\u5173\u952e\u5b57\u4e4b\u540e\u7684\u90a3\u4e2a\u51fd\u6570\u540d\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function k1 {};<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(k1.name); \/\/&#8217;k1&#8242;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var k2 = function {};<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(k2.name); \/\/&#8221;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var k3 = function hello {};<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(k3.name); \/\/&#8217;hello&#8217;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4e0a\u9762\u4ee3\u7801\u4e2d\uff0cname\u5c5e\u6027\u8fd4\u56defunction \u540e\u9762\u7d27\u8ddf\u7740\u7684\u51fd\u6570\u540d\u3002\u5bf9\u4e8ek2\u6765\u8bf4\uff0c\u8fd4\u56de\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\uff0c\u6ce8\u610f\uff1a<strong>\u533f\u540d\u51fd\u6570\u7684name\u5c5e\u6027\u603b\u662f\u4e3a\u7a7a\u5b57\u7b26\u4e32<\/strong>\u3002\u5bf9\u4e8ek3\u6765\u8bf4\uff0c\u8fd4\u56de\u51fd\u6570\u8868\u8fbe\u5f0f\u7684\u540d\u5b57\uff08\u771f\u6b63\u7684\u51fd\u6570\u540d\u4e3ak3\uff0chello\u8fd9\u4e2a\u51fd\u6570\u540d\u53ea\u80fd\u5728\u51fd\u6570\u5185\u90e8\u4f7f\u7528\u3002\uff09<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\"><strong>2.2<\/strong><strong>\uff1alength\u5c5e\u6027<\/strong><\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">length\u5c5e\u6027\u8fd4\u56de\u51fd\u6570\u9884\u671f\u4f20\u5165\u7684\u53c2\u6570\u4e2a\u6570\uff0c\u5373\u51fd\u6570\u5b9a\u4e49\u4e4b\u4e2d\u7684\u53c2\u6570\u4e2a\u6570\u3002\u8fd4\u56de\u7684\u662f\u4e2a\u6570\uff0c\u800c\u4e0d\u662f\u5177\u4f53\u53c2\u6570\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function fun(a, b, c, d, e) {}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(fun.length)\u00a0\u00a0\u00a0 \/\/ 5<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4e0a\u9762\u4ee3\u7801\u5b9a\u4e49\u4e86\u7a7a\u51fd\u6570fun\uff0c\u5b83\u7684length\u5c5e\u6027\u5c31\u662f\u5b9a\u4e49\u65f6\u7684\u53c2\u6570\u4e2a\u6570\u3002\u4e0d\u7ba1\u8c03\u7528\u65f6\u8f93\u5165\u4e86\u591a\u5c11\u4e2a\u53c2\u6570\uff0clength\u5c5e\u6027\u59cb\u7ec8\u7b49\u4e8e5\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u8c03\u7528\u65f6\u7ed9\u5b9e\u53c2\u4f20\u9012\u4e866\u4e2a\u53c2\u6570\uff0clength\u5c5e\u6027\u4f1a\u5ffd\u7565\u6389\u4e00\u4e2a\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\"><strong>2.3<\/strong><strong>\uff1atoString\u65b9\u6cd5<\/strong><\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u51fd\u6570\u7684toString\u65b9\u6cd5\u8fd4\u56de\u51fd\u6570\u7684\u4ee3\u7801\u672c\u8eab\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function fun(a, b, c, d, e) {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\/\/ \u8fd9\u662f\u6ce8\u91ca\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(fun.toString);<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\/\/function fun(a, b, c, d, e) {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\/\/ \u8fd9\u662f\u6ce8\u91ca\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u53ef\u4ee5\u770b\u5230\uff0c\u51fd\u6570\u5185\u90e8\u7684\u6ce8\u91ca\u6bb5\u4e5f\u88ab\u8fd4\u56de\u4e86\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\"><strong>3.1<\/strong><strong>\uff1a\u4f5c\u7528\u57df<\/strong><\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4f5c\u7528\u57df\uff08scope\uff09\u6307\u7684\u662f\u53d8\u91cf\u5b58\u5728\u7684\u8303\u56f4\u3002Javascript\u53ea\u6709\u4e24\u79cd\u4f5c\u7528\u57df\uff1a\u4e00\u79cd\u662f\u5168\u5c40\u4f5c\u7528\u57df\uff0c\u53d8\u91cf\u5728\u6574\u4e2a\u7a0b\u5e8f\u4e2d\u4e00\u76f4\u5b58\u5728\uff0c\u6240\u6709\u5730\u65b9\u90fd\u53ef\u4ee5\u8bfb\u53d6\uff0c\u5728\u5168\u5c40\u4f5c\u7528\u57df\u4e2d\u58f0\u660e\u7684\u53d8\u91cf\u79f0\u4e3a\u5168\u5c40\u53d8\u91cf\uff1b\u53e6\u4e00\u79cd\u662f\u5c40\u90e8\u4f5c\u7528\u57df\uff0c\u53d8\u91cf\u53ea\u5728\u51fd\u6570\u5185\u90e8\u5b58\u5728\uff0c\u6b64\u65f6\u7684\u53d8\u91cf\u88ab\u79f0\u4e3a\u5c40\u90e8\u53d8\u91cf\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u5728\u5168\u5c40\u4f5c\u7528\u57df\u4e2d\u58f0\u660e\u7684\u53d8\u91cf\u79f0\u4e3a\u5168\u5c40\u53d8\u91cf\uff0c\u4e5f\u5c31\u662f\u5728\u51fd\u6570\u5916\u90e8\u58f0\u660e\u3002\u5b83\u53ef\u4ee5\u5728\u51fd\u6570\u5185\u90e8\u8bfb\u53d6\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var a=1;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function fun(){<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">return a;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(fun())\u00a0\u00a0\u00a0 \/\/1<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4e0a\u9762\u4ee3\u7801\u4e2d\uff0c\u5168\u5c40\u4f5c\u7528\u57df\u4e0b\u7684\u51fd\u6570fun\u53ef\u4ee5\u5728\u5185\u90e8\u8bfb\u53d6\u5168\u5c40\u53d8\u91cfa\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u5728\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u7684\u53d8\u91cf\uff0c\u53ea\u80fd\u5728\u5185\u90e8\u8bbf\u95ee\uff0c\u5916\u90e8\u65e0\u6cd5\u8bfb\u53d6\uff0c\u79f0\u4e3a\u5c40\u90e8\u53d8\u91cf\u3002\u6ce8\u610f\u8fd9\u91cc\u5fc5\u987b\u662f<strong>\u5728\u51fd\u6570\u5185\u90e8\u58f0\u660e\u7684\u53d8\u91cf\u3002<\/strong><\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function fun(){<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var a=1;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">return a;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(a)\u00a0\u00a0\u00a0 \/\/Uncaught ReferenceError: a is not defined<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u5728\u4e0a\u9762\u4ee3\u7801\u4e2d\uff0c\u53d8\u91cfa\u5728\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\uff0c\u6240\u4ee5\u662f\u4e00\u4e2a\u5c40\u90e8\u53d8\u91cf\uff0c\u5916\u90e8\u65e0\u6cd5\u8bbf\u95ee\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u7684\u53d8\u91cf\uff0c\u4f1a\u5728\u8be5\u4f5c\u7528\u57df\u4e0b\u8986\u76d6\u540c\u540d\u53d8\u91cf\u3002\u6ce8\u610f\u4ee5\u4e0b\u4e24\u4e2a\u4ee3\u7801\u6bb5\u7684\u533a\u522b\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var a = 2;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function fun() {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var a = 1;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(a);<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">fun(); \/\/1<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var c = 2;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function rascal() {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var c = 1;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">return c;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(c); \/\/2<\/span><br \/>\n<span style=\"font-family: 'comic sans ms', sans-serif;\"> console.log(rascal()); \/\/1<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4e0a\u9762\u4ee3\u7801\u4e2d\uff0c\u53d8\u91cfa\u548cc\u540c\u65f6\u5728\u51fd\u6570\u7684\u5916\u90e8\u548c\u5185\u90e8\u6709\u5b9a\u4e49\u3002\u7ed3\u679c\uff0c\u5728\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\uff0c\u5c40\u90e8\u53d8\u91cfa\u8986\u76d6\u4e86\u5168\u5c40\u53d8\u91cfa\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u6ce8\u610f\uff0c\u5bf9\u4e8evar\u547d\u4ee4\u6765\u8bf4\uff0c\u5c40\u90e8\u53d8\u91cf\u53ea\u80fd\u5728\u51fd\u6570\u5185\u90e8\u58f0\u660e\u3002\u5728\u5176\u4ed6\u533a\u5757\u58f0\u660e\uff0c\u4e00\u5f8b\u90fd\u662f\u5168\u5c40\u53d8\u91cf\u3002\u6bd4\u5982\u8bf4if\u8bed\u53e5\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">if (true) {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var a=1;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(a);\u00a0\u00a0\u00a0 \/\/1<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4ece\u4e0a\u9762\u4ee3\u7801\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u53d8\u91cfa\u5728\u6761\u4ef6\u5224\u65ad\u533a\u5757\u4e4b\u4e2d\u58f0\u660e\uff0c\u7ed3\u679c\u5c31\u662f\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\uff0c\u53ef\u4ee5\u5728\u533a\u5757\u4e4b\u5916\u8bfb\u53d6\u3002\u4f46\u662f\u8fd9\u91cc\u5982\u679c\u91c7\u7528ES6\u4e2dlet\u5173\u952e\u5b57\uff0c\u5728\u5168\u5c40\u4f5c\u7528\u57df\u4e0b\u662f\u65e0\u6cd5\u8bbf\u95eea\u53d8\u91cf\u7684\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\"><strong>3.2<\/strong><strong>\uff1a\u51fd\u6570\u5185\u90e8\u7684\u53d8\u91cf\u58f0\u660e\u63d0\u5347<\/strong><\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4e0e\u5168\u5c40\u4f5c\u7528\u57df\u4e0b\u7684\u53d8\u91cf\u58f0\u660e\u63d0\u5347\u76f8\u540c\uff0c\u5c40\u90e8\u4f5c\u7528\u57df\u4e0b\u7684\u5c40\u90e8\u53d8\u91cf\u5728\u51fd\u6570\u5185\u90e8\u4e5f\u4f1a\u53d1\u751f\u53d8\u91cf\u58f0\u660e\u63d0\u5347\u3002var\u547d\u4ee4\u58f0\u660e\u7684\u53d8\u91cf\uff0c\u4e0d\u7ba1\u5728\u4ec0\u4e48\u4f4d\u7f6e\uff0c\u53d8\u91cf\u58f0\u660e\u90fd\u4f1a\u88ab\u63d0\u5347\u5230\u51fd\u6570\u4f53\u7684\u5934\u90e8\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function fun(a) {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">if (a > 10) {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var b = a &#8211; 10;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function fun(a) {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var b;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">if (a > 10) {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">b = a &#8211; 10;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4e0a\u9762\u4e24\u4e2a\u51fd\u6570\u6bb5\u662f\u76f8\u540c\u7684\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\"><strong>3.3<\/strong><strong>\uff1a\u51fd\u6570\u672c\u8eab\u7684\u4f5c\u7528\u57df<\/strong><\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u51fd\u6570\u672c\u8eab\u4e5f\u662f\u4e00\u4e2a\u503c\uff0c\u4e5f\u6709\u81ea\u5df1\u7684\u4f5c\u7528\u57df\u3002\u5b83\u7684\u4f5c\u7528\u57df\u4e0e\u53d8\u91cf\u4e00\u6837\uff0c\u5c31\u662f\u5176\u58f0\u660e\u65f6\u6240\u5728\u7684\u4f5c\u7528\u57df\uff0c\u4e0e\u5176\u8fd0\u884c\u65f6\u6240\u5728\u7684\u4f5c\u7528\u57df\u65e0\u5173\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var a = 1;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var b = function {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(a);<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">};<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function c {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var a = 2;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">b;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">c(); \/\/110<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var a = 1;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var b = function {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">return a;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">};<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function c {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var a = 2;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">return b;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(c()); \/\/1<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4ee5\u4e0a\u4e24\u4e2a\u4ee3\u7801\u6bb5\u76f8\u540c\u3002\u51fd\u6570b\u662f\u5728\u51fd\u6570c\u5916\u90e8\u58f0\u660e\u7684\u3002\u6240\u4ee5\u5b83\u7684\u4f5c\u7528\u57df\u7ed1\u5b9a\u5728\u51fd\u6570\u5916\u5c42\uff0c\u5185\u90e8\u51fd\u6570a\u4e0d\u4f1a\u5230\u51fd\u6570c\u4f53\u5185\u53d6\u503c\uff0c\u6240\u4ee5\u8fd4\u56de\u7684\u662f1\uff0c\u800c\u4e0d\u662f2\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u5f88\u5bb9\u6613\u72af\u9519\u7684\u4e00\u70b9\u662f\uff0c\u5982\u679c\u51fd\u6570A\u8c03\u7528\u51fd\u6570B\uff0c\u5374\u6ca1\u8003\u8651\u5230\u51fd\u6570B\u4e0d\u4f1a\u5f15\u7528\u51fd\u6570A\u7684\u5185\u90e8\u53d8\u91cf\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var b = function {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(a);<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">};<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function c(f) {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var a = 1;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">f;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">c(b); \/\/Uncaught ReferenceError: a is not defined<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var b = function {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">return a;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">};<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function c(f) {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var a = 1;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">return f;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(c(b)); \/\/Uncaught ReferenceError: a is not defined<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4e0a\u9762\u4ee3\u7801\u5c06\u51fd\u6570b\u4f5c\u4e3a\u53c2\u6570\uff0c\u4f20\u5165\u51fd\u6570c\u3002\u4f46\u662f\uff0c\u51fd\u6570b\u662f\u5728\u51fd\u6570c\u4f53\u5916\u58f0\u660e\u7684\uff0c\u4f5c\u7528\u57df\u7ed1\u5b9a\u5916\u5c42\uff0c\u56e0\u6b64\u627e\u4e0d\u5230\u51fd\u6570c\u7684\u5185\u90e8\u53d8\u91cfa\uff0c\u5bfc\u81f4\u62a5\u9519\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u540c\u6837\u7684\uff0c\u51fd\u6570\u4f53\u5185\u90e8\u58f0\u660e\u7684\u53d8\u91cf\uff0c\u4f5c\u7528\u57df\u7ed1\u5b9a\u5728\u51fd\u6570\u4f53\u5185\u90e8\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function fun() {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var a = 1;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">function rascal {<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">console.log(a);<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">return rascal;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">}<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var a = 2;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">var f = fun;<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">f(); \/\/1<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\">\u4e0a\u9762\u4ee3\u7801\u4e2d\uff0c\u51fd\u6570fun\u5185\u90e8\u58f0\u660e\u4e86rascal\u53d8\u91cf\u3002rascal\u4f5c\u7528\u57df\u7ed1\u5b9a\u5728fun\u4e0a\u3002\u5f53\u6211\u4eec\u5728fun\u5916\u90e8\u53d6\u51farascal\u6267\u884c\u65f6\uff0c\u53d8\u91cfa\u6307\u5411\u7684\u662ffun\u5185\u90e8\u7684a\uff0c\u800c\u4e0d\u662ffun\u5916\u90e8\u7684a\u3002\u8fd9\u91cc\u6d89\u53ca\u5230\u51fd\u6570\u53e6\u5916\u4e00\u4e2a\u91cd\u8981\u7684\u77e5\u8bc6\u70b9\uff0c\u5373\u5728\u4e00\u4e2a\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u53e6\u5916\u4e00\u4e2a\u51fd\u6570\uff0c\u4e5f\u5c31\u662f\u95ed\u5305\u7684\u6982\u5ff5\u3002<\/span><\/p>\n<p><span style=\"font-family: 'comic sans ms', sans-serif;\"><strong>\u603b\u4e4b\uff0c\u51fd\u6570\u6267\u884c\u65f6\u6240\u5728\u7684\u4f5c\u7528\u57df\uff0c\u662f\u5b9a\u4e49\u65f6\u7684\u4f5c\u7528\u57df\uff0c\u800c\u4e0d\u662f\u8c03\u7528\u65f6\u6240\u5728\u7684\u4f5c\u7528\u57df\u3002<\/strong><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.1\u51fd\u6570\u58f0\u660e \u51fd\u6570\u5c31\u662f\u4e00\u6bb5\u53ef\u4ee5\u53cd\u590d\u8c03\u7528\u7684\u4ee3\u7801\u5757\u3002\u51fd\u6570\u58f0\u660e\u7531\u4e09\u90e8\u5206\u7ec4\u6210\uff1a\u51fd\u6570\u540d\uff0c\u51fd\u6570\u53c2\u6570\uff0c\u51fd\u6570\u4f53\u3002\u6574<a href=\"https:\/\/blog.indeex.club\/index.php\/2011\/10\/14\/ecmascript-5-%e5%87%bd%e6%95%b0%e5%9f%ba%e7%a1%80\/\" class=\"read-more\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[4],"_links":{"self":[{"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/posts\/58"}],"collection":[{"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/comments?post=58"}],"version-history":[{"count":1,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":59,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/posts\/58\/revisions\/59"}],"wp:attachment":[{"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/media?parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/categories?post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/tags?post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}