{"id":70,"date":"2021-01-17T19:39:47","date_gmt":"2021-01-17T11:39:47","guid":{"rendered":"http:\/\/gjweb.top\/?p=70"},"modified":"2021-01-17T19:54:53","modified_gmt":"2021-01-17T11:54:53","slug":"ecmascript-5","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=70","title":{"rendered":"ECMAScript 5"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e25\u683c\u6a21\u5f0f<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b9a\u4e49<\/li><li>\u6bd4\u4f20\u7edfjs\u8fd0\u884c\u673a\u5236\u8981\u6c42\u66f4\u4e3a\u4e25\u683c\u7684\u6a21\u5f0f<\/li><li>\u539f\u56e0<\/li><li>js\u672c\u8eab\u6709\u5f88\u591a\u5e7f\u53d7\u8bdf\u75c5\u7684\u7f3a\u9677<\/li><li>\u4f55\u65f6\u7528<\/li><li>\u4eca\u540e\u6240\u6709\u9879\u76ee\u5f00\u53d1,\u90fd\u5fc5\u987b\u5728\u4e25\u683c\u6a21\u5f0f\u4e0b\u8fdb\u884c<\/li><li>\u5982\u4f55\u7528<\/li><li>\u4e24\u4e2a\u8303\u56f4<ul><li>\u5728\u6574\u4e2ajs\u6587\u4ef6\u6216<strong>script<\/strong>\u6807\u7b7e\u5185\u542f\u7528\u4e25\u683c\u6a21\u5f0f<\/li><li>\u5728js\u6587\u4ef6\u6216\u8005 <strong>script<\/strong>\u6807\u7b7e\u5185 <strong>&#8220;use strict&#8221;<\/strong><\/li><li>\u5c3d\u5728\u5355\u4e2a\u51fd\u6570\u5185\u542f\u7528\u4e25\u683c\u6a21\u5f0f<\/li><li>\u5728\u51fd\u6570\u5185\u7684\u7b2c\u4e00\u884c <strong>&#8220;use strict&#8221;<\/strong><\/li><\/ul><\/li><li>\u8981\u6c42<\/li><li>\u7981\u6b62\u7ed9\u4e3a\u58f0\u660e\u7684\u53d8\u91cf\u8d4b\u503c<\/li><li>\u5c06\u9759\u9ed8\u5931\u8d25\u5347\u7ea7\u4e3a\u9519\u8bef<ul><li>\u9759\u9ed8\u5931\u8d25 &#8212; \u4fee\u6539\u4e0d\u6210\u529f,\u53c8\u4e0d\u62a5\u9519!<\/li><\/ul><\/li><li>\u4e0d\u5efa\u8bae\u4f7f\u7528 <strong>arguments<\/strong> \\ <strong>arguments.callee<\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u89e3\u51b3\u65b9\u6cd5\r\nvar fun = (function fn(num){\r\n    if(num &lt;= 1){\r\n        return 1\r\n    }else{\r\n        return num * f(num-1)\r\n    }\r\n})<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u666e\u901a\u51fd\u6570\u8c03\u7528\u548c\u533f\u540d\u51fd\u6570\u81ea\u8c03\u4e2d\u7684this \u4e0d\u5728\u6307\u5411window\u800c\u662f undefined<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u5bf9\u5bf9\u8c61\u7684\u4fdd\u62a4<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b9a\u4e49<\/li><li>js \u4e2d\u666e\u901a\u5bf9\u8c61\u5bf9\u81ea\u5df1\u7684\u5c5e\u6027\u548c\u89e3\u6784,\u6ca1\u6709\u4efb\u4f55\u9a8c\u8bc1\u548c\u4fdd\u62a4\u7684\u529e\u6cd5<\/li><li>\u7528\u5904<\/li><li>\u5de6\u53f3\u5bf9\u8c61\u90fd\u8981\u5bf9\u81ea\u5df1\u7684\u5c5e\u6027\u63d0\u4f9b\u4e00\u5b9a\u7684\u4fdd\u62a4<\/li><li>\u5982\u4f55\u7528<\/li><li>\u4fdd\u62a4\u5c5e\u6027<ul><li>es5 \u89c4\u5b9a: \u5bf9\u8c61\u7684\u5c5e\u6027\u5206\u4e3a2\u5927\u7c7b<\/li><li>\u547d\u540d\u5c5e\u6027: \u53ef\u7528 <strong>.<\/strong>\u76f4\u63a5\u8bbf\u95ee\u7684\u5c5e\u6027<\/li><li>\u7ec6\u5206\u4e3a\u4e24\u7c7b<ul><li>\u6570\u636e\u5c5e\u6027: \u76f4\u63a5\u5b58\u50a8\u5c5e\u6027\u503c\u7684\u5c5e\u6027<\/li><li>\u5982\u4f55\u4fdd\u62a4 : \u6bcf\u4e2a\u6570\u636e\u5c5e\u6027\u4e0d\u5728\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u53d8\u91cf,\u800c\u662f\u4e00\u4e2a\u62e5\u6709\u56db\u5927\u7279\u5b9a\u7684\u5c0f\u5bf9\u8c61<\/li><li>\u67e5\u770b\u4e00\u4e2a\u5c5e\u6027\u7684\u56db\u5927\u7279\u6027<\/li><\/ul><\/li><\/ul><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Object.getOwnPropertyDescriptor(obj,'\u5c5e\u6027\u540d')\r\n\/\/\u8fd4\u56de\u503c\r\n{\r\n    value : \u5b9e\u9645\u5b58\u50a8\u5c5e\u6027\u503c\r\n    writable: bool \u63a7\u5236\u53ea\u8bfb\r\n    enumerable: bool \u63a7\u5236\u662f\u5426\u88abfor...in \u904d\u5386\u5230,(\u4ecd\u53ef\u4ee5\u8bbf\u95ee)\r\n    configurable: bool \u63a7\u5236\r\n    \t\/*\r\n    \t\t1. \u63a7\u5236\u80fd\u5426\u5220\u9664\u8be5\u5c5e\u6027\r\n    \t\t2. \u63a7\u5236\u80fd\u5426\u4fee\u6539\u5176\u4ed6\u7279\u6027\r\n    \t\t\t\u4e00\u65e6\u6539\u4e3afalse,\u4e0d\u53ef\u9006\r\n    \t\t\t\u603b\u662f\u4f34\u968f\u5176\u4ed6\u7684\u4fee\u6539,\u5145\u5f53\u53cc\u4fdd\u9669\r\n    \t*\/\r\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5982\u4f55\u4fee\u6539\u56db\u5927\u7279\u6027\u4fdd\u62a4\u6570\u636e\u5c5e\u6027<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Object.defineProperty(obj,\"\u5c5e\u6027\u540d\",{\r\n    \u8981\u4fee\u6539\u7684\u7279\u6027: \u503c,\r\n    ...\r\n})<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u95ee\u9898: \u4e00\u6b21\u53ea\u80fd\u4fee\u6539\u4e00\u4e2a\u5c5e\u6027\u7684\u56db\u5927\u7279\u6027<ul><li>\u89e3\u51b3: \u540c\u65f6\u4fee\u6539\u591a\u4e2a\u5c5e\u6027\u7684\u56db\u5927\u7279\u6027<\/li><\/ul><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Object.defineProperties(obj,{\r\n    \u5c5e\u6027\u540d:{\r\n        \u56db\u5927\u7279\u6027: \u503c,\r\n        ...\r\n    },\r\n    \u5c5e\u6027\u540d:{\r\n    \t\u56db\u5927\u7279\u6027: \u503c,\r\n        ...\r\n    }\r\n})<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u8bf4\u660e: \u5982\u679c\u8981\u4fee\u6539\u7684\u5c5e\u6027\u4e0d\u5b58\u5728,\u5219\u81ea\u52a8\u521b\u5efa,\u4f46\u662f,\u81ea\u52a8\u521b\u5efa\u7684\u5c5e\u6027,\u56db\u5927\u9ed8\u8ba4\u503c\u90fd\u662ffalse<ul><li>\u95ee\u9898: \u53ea\u80fd\u7528\u56fa\u5b9a\u7684\u4e09\u79cd\u7279\u6027\u4fdd\u62a4\u5c5e\u6027, \u65e0\u6cd5\u81ea\u5b9a\u4e49\u89c4\u5219\u9886\u8fc7\u4fdd\u62a4\u5c5e\u6027<\/li><\/ul><ul><li><strong>\u8bbf\u95ee\u5668\u5c5e\u6027<\/strong><ul><li>\u8bbf\u95ee\u5668\u5c5e\u6027\u4e0d\u5305\u542b\u6570\u636e\u503c; \u4f46\u5305\u542b<strong>get<\/strong> \u548c <strong>set<\/strong> \u51fd\u6570,\u8d1f\u8d23\u8bfb\u53d6\u5728\u8bbf\u95ee\u5668\u65f6\u8c03\u7528<strong>get<\/strong>\u51fd\u6570,\u5728\u5199\u5165\u8bbf\u95ee\u5668\u65f6\u8c03\u7528<strong>set<\/strong>\u51fd\u6570<\/li><li><strong>\u6ce8\u610f<\/strong> : \u8be5\u65b9\u6cd5\u5fc5\u987b\u901a\u8fc7 <strong>Object.defionPropertype()<\/strong> \u6765\u5b9a\u4e49<\/li><\/ul><\/li><\/ul><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">call \\ apply \\ bind<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u76f8\u540c\u70b9<\/li><li>\u5982\u679c\u51fd\u6570\u4e2dthis\u4e0d\u662f\u60f3\u8981\u7684,\u90fd\u53ef\u4ee5\u66ff\u6362<\/li><li>\u4e0d\u540c\u70b9<\/li><li>call \/ apply : \u5f3a\u884c\u8c03\u7528\u4e00\u4e2a\u51fd\u6570,\u5e76\u4e34\u65f6\u66ff\u6362\u51fd\u6570\u4e2d\u7684this\u4e3a\u6307\u5b9a\u7684\u5bf9\u8c61<\/li><li>call: \u8981\u6c42\u4f20\u5165\u51fd\u6570\u7684\u53c2\u6570\u5fc5\u987b\u5355\u72ec\u4f20\u5165<\/li><li>apply: \u8981\u6c42\u4f20\u5165\u51fd\u6570\u7684\u53c2\u6570\u5fc5\u987b\u653e\u5728\u6570\u7ec4\u4e2d\u6574\u4f53\u4f20\u5165<ul><li>apply \u53ef\u5148\u6253\u6563\u6570\u7ec4\u53c2\u6570\u4e3a\u5355\u4e2a\u5143\u7d20,\u5728\u4f20\u53c2<\/li><\/ul><\/li><li>bind : \u57fa\u4e8e\u4e00\u4e2a\u73b0\u6709\u51fd\u6570,\u521b\u5efa\u4e00\u4e2a\u4e00\u6a21\u4e00\u6837\u7684\u65b0\u51fd\u6570,\u5e76\u60a0\u4e45\u7ed1\u5b9athis\u4e3a\u6307\u5b9a\u5bf9\u8c61<\/li><li>\u7528\u9014<\/li><li>\u53ef\u6269\u5927\u51fd\u6570\u7684\u8fd0\u884c\u7684\u4f5c\u7528\u57df<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>window.color = \"red\"\r\nvar o = {color:\"blue\"}\r\nfunction saycolor(){\r\n    console.log(this.color)\r\n}\r\nsaycolor.call(this) \/\/red\r\nsaycolor.call(window) \/\/red\r\nsaycolor.call(o) \/\/blue<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u603b\u7ed3<\/li><li>\u5982\u679c\u662f\u4e34\u65f6\u8c03\u7528\u4e00\u4e2a\u51fd\u6570,\u7528call \/ apply<\/li><li>\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u65b0\u51fd\u6570,\u6c38\u4e45\u7ed1\u5b9athis\u65f6<\/li><li>\u6240\u6709\u56de\u89c1\u51fd\u6570\u4e2d\u7684this,\u8981\u60f3\u66ff\u6362\u90fd\u7528bind<ul><li>\u56e0\u4e3a\u56de\u8c03\u51fd\u6570\u4e0d\u662f\u7acb\u5373\u6267\u884c,\u4e14\u4e0d\u6b62\u6267\u884c\u4e00\u6b21<\/li><\/ul><\/li><li>\u8865\u5145<\/li><li>bind\u4f7f\u7528\u65b9\u6cd5<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>this.a = 1;\r\nvar module = {\r\n    a:2,\r\n    getA:function(){\r\n        return this.a\r\n    }\r\n}\r\nconsole.log(module.getA());\r\n\r\n\/\/test \u5728\u5916\u90e8\u8c03\u7528,\u6b64\u65f6\u7684this\u6307\u5411\u4e86\u5168\u5c40\r\nvar test = module.getA;\r\nconsole.log(test()); \/\/1\r\n\/\/\u518d\u628atestA\u65b9\u6cd5\u7ed1\u5b9a\u5230module\u73af\u5883\u4e0a\r\nvar testA = test.bind(module);\r\nconsole.log(testA()) \/\/2<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e25\u683c\u6a21\u5f0f \u5b9a\u4e49 \u6bd4\u4f20\u7edfjs\u8fd0\u884c\u673a\u5236\u8981\u6c42\u66f4\u4e3a\u4e25\u683c\u7684\u6a21\u5f0f \u539f\u56e0 js\u672c\u8eab\u6709\u5f88\u591a\u5e7f\u53d7\u8bdf\u75c5\u7684\u7f3a\u9677 \u4f55\u65f6\u7528 \u4eca\u540e\u6240\u6709\u9879\u76ee [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-70","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/70","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=70"}],"version-history":[{"count":0,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/70\/revisions"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}