{"id":2727,"date":"2020-04-16T16:33:37","date_gmt":"2020-04-16T08:33:37","guid":{"rendered":"http:\/\/www.yuguoxy.com\/geekhome\/?p=2727"},"modified":"2020-04-18T11:11:34","modified_gmt":"2020-04-18T03:11:34","slug":"%e5%89%8d%e7%ab%afjs%e7%9b%b8%e5%85%b3%e7%9f%a5%e8%af%86","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=2727","title":{"rendered":"\u524d\u7aefjavascript\u9ad8\u7ea7"},"content":{"rendered":"<blockquote><p>\u672c\u6587\u5c06\u4ece\u4ee5\u4e0b\u5341\u4e00\u4e2a\u7ef4\u5ea6\u4e3a\u8bfb\u8005\u603b\u7ed3\u524d\u7aef\u57fa\u7840\u77e5\u8bc6<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/17150295c4bb639b.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-2729\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/17150295c4bb639b.png\" alt=\"17150295c4bb639b\" width=\"1127\" height=\"998\" \/><\/a><\/p>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/aa.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2741\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/aa.png\" alt=\"aa\" width=\"280\" height=\"630\" \/><\/a><\/p>\n<h1>JS\u57fa\u7840<\/h1>\n<h2>1. \u5982\u4f55\u5728ES5\u73af\u5883\u4e0b\u5b9e\u73b0let<\/h2>\n<blockquote><p>\u5bf9\u4e8e\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u67e5\u770b<code>babel<\/code>\u8f6c\u6362\u524d\u540e\u7684\u7ed3\u679c\uff0c\u770b\u4e00\u4e0b\u5728\u5faa\u73af\u4e2d\u901a\u8fc7<code>let<\/code>\u5b9a\u4e49\u7684\u53d8\u91cf\u662f\u5982\u4f55\u89e3\u51b3\u53d8\u91cf\u63d0\u5347\u7684\u95ee\u9898<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/1714616e2fd53bf8.jpg\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-2730\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/1714616e2fd53bf8.jpg\" alt=\"1714616e2fd53bf8\" width=\"1312\" height=\"419\" \/><\/a><\/p>\n<p>babel\u5728let\u5b9a\u4e49\u7684\u53d8\u91cf\u524d\u52a0\u4e86\u9053\u4e0b\u5212\u7ebf\uff0c\u907f\u514d\u5728\u5757\u7ea7\u4f5c\u7528\u57df\u5916\u8bbf\u95ee\u5230\u8be5\u53d8\u91cf\uff0c\u9664\u4e86\u5bf9\u53d8\u91cf\u540d\u7684\u8f6c\u6362\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7\u81ea\u6267\u884c\u51fd\u6570\u6765\u6a21\u62df\u5757\u7ea7\u4f5c\u7528\u57df<\/p>\n<p>&nbsp;<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">(function(){\r\n  for(var i = 0; i &lt; 5; i ++){\r\n    console.log(i)  \/\/ 0 1 2 3 4\r\n  }\r\n})();\r\n\r\nconsole.log(i)      \/\/ Uncaught ReferenceError: i is not defined\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h2>2. \u5982\u4f55\u5728ES5\u73af\u5883\u4e0b\u5b9e\u73b0const<\/h2>\n<p>\u5b9e\u73b0const\u7684\u5173\u952e\u5728\u4e8e<code>Object.defineProperty()<\/code>\u8fd9\u4e2aAPI\uff0c\u8fd9\u4e2aAPI\u7528\u4e8e\u5728\u4e00\u4e2a\u5bf9\u8c61\u4e0a\u589e\u52a0\u6216\u4fee\u6539\u5c5e\u6027\u3002\u901a\u8fc7\u914d\u7f6e\u5c5e\u6027\u63cf\u8ff0\u7b26\uff0c\u53ef\u4ee5\u7cbe\u786e\u5730\u63a7\u5236\u5c5e\u6027\u884c\u4e3a\u3002<code>Object.defineProperty()<\/code> \u63a5\u6536\u4e09\u4e2a\u53c2\u6570\uff1a<\/p>\n<blockquote><p>Object.defineProperty(obj, prop, desc)<\/p><\/blockquote>\n<figure>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u53c2\u6570<\/th>\n<th style=\"text-align: center;\">\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">obj<\/td>\n<td style=\"text-align: center;\">\u8981\u5728\u5176\u4e0a\u5b9a\u4e49\u5c5e\u6027\u7684\u5bf9\u8c61<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">prop<\/td>\n<td style=\"text-align: center;\">\u8981\u5b9a\u4e49\u6216\u4fee\u6539\u7684\u5c5e\u6027\u7684\u540d\u79f0<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">descriptor<\/td>\n<td style=\"text-align: center;\">\u5c06\u88ab\u5b9a\u4e49\u6216\u4fee\u6539\u7684\u5c5e\u6027\u63cf\u8ff0\u7b26<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>&nbsp;<\/p>\n<figure>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u5c5e\u6027\u63cf\u8ff0\u7b26<\/th>\n<th style=\"text-align: left;\">\u8bf4\u660e<\/th>\n<th style=\"text-align: center;\">\u9ed8\u8ba4\u503c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">value<\/td>\n<td style=\"text-align: left;\">\u8be5\u5c5e\u6027\u5bf9\u5e94\u7684\u503c\u3002\u53ef\u4ee5\u662f\u4efb\u4f55\u6709\u6548\u7684 JavaScript \u503c\uff08\u6570\u503c\uff0c\u5bf9\u8c61\uff0c\u51fd\u6570\u7b49\uff09\u3002\u9ed8\u8ba4\u4e3a undefined<\/td>\n<td style=\"text-align: center;\">undefined<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">get<\/td>\n<td style=\"text-align: left;\">\u4e00\u4e2a\u7ed9\u5c5e\u6027\u63d0\u4f9b getter \u7684\u65b9\u6cd5\uff0c\u5982\u679c\u6ca1\u6709 getter \u5219\u4e3a undefined<\/td>\n<td style=\"text-align: center;\">undefined<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">set<\/td>\n<td style=\"text-align: left;\">\u4e00\u4e2a\u7ed9\u5c5e\u6027\u63d0\u4f9b setter \u7684\u65b9\u6cd5\uff0c\u5982\u679c\u6ca1\u6709 setter \u5219\u4e3a undefined\u3002\u5f53\u5c5e\u6027\u503c\u4fee\u6539\u65f6\uff0c\u89e6\u53d1\u6267\u884c\u8be5\u65b9\u6cd5<\/td>\n<td style=\"text-align: center;\">undefined<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">writable<\/td>\n<td style=\"text-align: left;\">\u5f53\u4e14\u4ec5\u5f53\u8be5\u5c5e\u6027\u7684writable\u4e3atrue\u65f6\uff0cvalue\u624d\u80fd\u88ab\u8d4b\u503c\u8fd0\u7b97\u7b26\u6539\u53d8\u3002\u9ed8\u8ba4\u4e3a false<\/td>\n<td style=\"text-align: center;\">false<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">enumerable<\/td>\n<td style=\"text-align: left;\">enumerable\u5b9a\u4e49\u4e86\u5bf9\u8c61\u7684\u5c5e\u6027\u662f\u5426\u53ef\u4ee5\u5728 for&#8230;in \u5faa\u73af\u548c Object.keys() \u4e2d\u88ab\u679a\u4e3e<\/td>\n<td style=\"text-align: center;\">false<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">Configurable<\/td>\n<td style=\"text-align: left;\">configurable\u7279\u6027\u8868\u793a\u5bf9\u8c61\u7684\u5c5e\u6027\u662f\u5426\u53ef\u4ee5\u88ab\u5220\u9664\uff0c\u4ee5\u53ca\u9664value\u548cwritable\u7279\u6027\u5916\u7684\u5176\u4ed6\u7279\u6027\u662f\u5426\u53ef\u4ee5\u88ab\u4fee\u6539<\/td>\n<td style=\"text-align: center;\">false<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>\u5bf9\u4e8econst\u4e0d\u53ef\u4fee\u6539\u7684\u7279\u6027\uff0c\u6211\u4eec\u901a\u8fc7\u8bbe\u7f6ewritable\u5c5e\u6027\u6765\u5b9e\u73b0<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">function _const(key, value) {    \r\n    const desc = {        \r\n        value,        \r\n        writable: false    \r\n    }    \r\n    Object.defineProperty(window, key, desc)\r\n}\r\n    \r\n_const('obj', {a: 1})   \/\/\u5b9a\u4e49obj\r\nobj.b = 2               \/\/\u53ef\u4ee5\u6b63\u5e38\u7ed9obj\u7684\u5c5e\u6027\u8d4b\u503c\r\nobj = {}                \/\/\u629b\u51fa\u9519\u8bef\uff0c\u63d0\u793a\u5bf9\u8c61read-only\r\n\r\n<\/code><\/pre>\n<p>\u53c2\u8003\u8d44\u6599\uff1a<a href=\"https:\/\/juejin.im\/post\/5ce3b2d451882533287a767f\">\u5982\u4f55\u5728 ES5 \u73af\u5883\u4e0b\u5b9e\u73b0\u4e00\u4e2aconst \uff1f<\/a><\/p>\n<h2>3. \u624b\u5199call()<\/h2>\n<blockquote>\n<pre><code>call() \u65b9\u6cd5`\u4f7f\u7528\u4e00\u4e2a\u6307\u5b9a\u7684 this \u503c\u548c\u5355\u72ec\u7ed9\u51fa\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u53c2\u6570\u6765\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\r\n\u8bed\u6cd5\uff1a`function.call(thisArg, arg1, arg2, ...)\r\n<\/code><\/pre>\n<\/blockquote>\n<p><code>call()<\/code>\u7684\u539f\u7406\u6bd4\u8f83\u7b80\u5355\uff0c\u7531\u4e8e\u51fd\u6570\u7684this\u6307\u5411\u5b83\u7684\u76f4\u63a5\u8c03\u7528\u8005\uff0c\u6211\u4eec\u53d8\u66f4\u8c03\u7528\u8005\u5373\u5b8c\u6210this\u6307\u5411\u7684\u53d8\u66f4\uff1a<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">\/\/\u53d8\u66f4\u51fd\u6570\u8c03\u7528\u8005\u793a\u4f8b\r\nfunction foo() {\r\n    console.log(this.name)\r\n}\r\n\r\n\/\/ \u6d4b\u8bd5\r\nconst obj = {\r\n    name: '\u5199\u4ee3\u7801\u50cf\u8521\u5f90\u62bb'\r\n}\r\nobj.foo = foo   \/\/ \u53d8\u66f4foo\u7684\u8c03\u7528\u8005\r\nobj.foo()       \/\/ '\u5199\u4ee3\u7801\u50cf\u8521\u5f90\u62bb'\r\n\r\n<\/code><\/pre>\n<p>\u57fa\u4e8e\u4ee5\u4e0a\u539f\u7406, \u6211\u4eec\u4e24\u53e5\u4ee3\u7801\u5c31\u80fd\u5b9e\u73b0call()<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">Function.prototype.myCall = function(thisArg, ...args) {\r\n    thisArg.fn = this              \/\/ this\u6307\u5411\u8c03\u7528call\u7684\u5bf9\u8c61,\u5373\u6211\u4eec\u8981\u6539\u53d8this\u6307\u5411\u7684\u51fd\u6570\r\n    return thisArg.fn(...args)     \/\/ \u6267\u884c\u51fd\u6570\u5e76return\u5176\u6267\u884c\u7ed3\u679c\r\n}\r\n\r\n<\/code><\/pre>\n<p>\u4f46\u662f\u6211\u4eec\u6709\u4e00\u4e9b\u7ec6\u8282\u9700\u8981\u5904\u7406\uff1a<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">Function.prototype.myCall = function(thisArg, ...args) {\r\n    const fn = Symbol('fn')        \/\/ \u58f0\u660e\u4e00\u4e2a\u72ec\u6709\u7684Symbol\u5c5e\u6027, \u9632\u6b62fn\u8986\u76d6\u5df2\u6709\u5c5e\u6027\r\n    thisArg = thisArg || window    \/\/ \u82e5\u6ca1\u6709\u4f20\u5165this, \u9ed8\u8ba4\u7ed1\u5b9awindow\u5bf9\u8c61\r\n    thisArg[fn] = this              \/\/ this\u6307\u5411\u8c03\u7528call\u7684\u5bf9\u8c61,\u5373\u6211\u4eec\u8981\u6539\u53d8this\u6307\u5411\u7684\u51fd\u6570\r\n    const result = thisArg[fn](...args)  \/\/ \u6267\u884c\u5f53\u524d\u51fd\u6570\r\n    delete thisArg[fn]              \/\/ \u5220\u9664\u6211\u4eec\u58f0\u660e\u7684fn\u5c5e\u6027\r\n    return result                  \/\/ \u8fd4\u56de\u51fd\u6570\u6267\u884c\u7ed3\u679c\r\n}\r\n\r\n\/\/\u6d4b\u8bd5\r\nfoo.myCall(obj)     \/\/ \u8f93\u51fa'\u5199\u4ee3\u7801\u50cf\u8521\u5f90\u62bb'\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h2>4. \u624b\u5199apply()<\/h2>\n<blockquote><p>apply() \u65b9\u6cd5\u8c03\u7528\u4e00\u4e2a\u5177\u6709\u7ed9\u5b9athis\u503c\u7684\u51fd\u6570\uff0c\u4ee5\u53ca\u4f5c\u4e3a\u4e00\u4e2a\u6570\u7ec4\uff08\u6216\u7c7b\u4f3c\u6570\u7ec4\u5bf9\u8c61\uff09\u63d0\u4f9b\u7684\u53c2\u6570\u3002<br \/>\n\u8bed\u6cd5\uff1afunc.apply(thisArg, [argsArray])<\/p><\/blockquote>\n<p><code>apply()<\/code>\u548c<code>call()<\/code>\u7c7b\u4f3c\uff0c\u533a\u522b\u5728\u4e8ecall()\u63a5\u6536\u53c2\u6570\u5217\u8868\uff0c\u800capply()\u63a5\u6536\u4e00\u4e2a\u53c2\u6570\u6570\u7ec4\uff0c\u6240\u4ee5\u6211\u4eec\u5728call()\u7684\u5b9e\u73b0\u4e0a\u7b80\u5355\u6539\u4e00\u4e0b\u5165\u53c2\u5f62\u5f0f\u5373\u53ef<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">Function.prototype.myApply = function(thisArg, args) {\r\n    const fn = Symbol('fn')        \/\/ \u58f0\u660e\u4e00\u4e2a\u72ec\u6709\u7684Symbol\u5c5e\u6027, \u9632\u6b62fn\u8986\u76d6\u5df2\u6709\u5c5e\u6027\r\n    thisArg = thisArg || window    \/\/ \u82e5\u6ca1\u6709\u4f20\u5165this, \u9ed8\u8ba4\u7ed1\u5b9awindow\u5bf9\u8c61\r\n    thisArg[fn] = this              \/\/ this\u6307\u5411\u8c03\u7528call\u7684\u5bf9\u8c61,\u5373\u6211\u4eec\u8981\u6539\u53d8this\u6307\u5411\u7684\u51fd\u6570\r\n    const result = thisArg[fn](...args)  \/\/ \u6267\u884c\u5f53\u524d\u51fd\u6570\r\n    delete thisArg[fn]              \/\/ \u5220\u9664\u6211\u4eec\u58f0\u660e\u7684fn\u5c5e\u6027\r\n    return result                  \/\/ \u8fd4\u56de\u51fd\u6570\u6267\u884c\u7ed3\u679c\r\n}\r\n\r\n\/\/\u6d4b\u8bd5\r\nfoo.myApply(obj, [])     \/\/ \u8f93\u51fa'\u5199\u4ee3\u7801\u50cf\u8521\u5f90\u62bb'\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h2>5. \u624b\u5199bind()<\/h2>\n<blockquote><p><code>bind()<\/code> \u65b9\u6cd5\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u51fd\u6570\uff0c\u5728 bind() \u88ab\u8c03\u7528\u65f6\uff0c\u8fd9\u4e2a\u65b0\u51fd\u6570\u7684 this \u88ab\u6307\u5b9a\u4e3a bind() \u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u800c\u5176\u4f59\u53c2\u6570\u5c06\u4f5c\u4e3a\u65b0\u51fd\u6570\u7684\u53c2\u6570\uff0c\u4f9b\u8c03\u7528\u65f6\u4f7f\u7528\u3002<br \/>\n\u8bed\u6cd5: function.bind(thisArg, arg1, arg2, &#8230;)<\/p><\/blockquote>\n<p>\u4ece\u7528\u6cd5\u4e0a\u770b\uff0c\u4f3c\u4e4e\u7ed9call\/apply\u5305\u4e00\u5c42function\u5c31\u5b9e\u73b0\u4e86bind()\uff1a<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">Function.prototype.myBind = function(thisArg, ...args) {\r\n    return () =&gt; {\r\n        this.apply(thisArg, args)\r\n    }\r\n}\r\n\r\n<\/code><\/pre>\n<p>\u4f46\u6211\u4eec\u5ffd\u7565\u4e86\u4e09\u70b9\uff1a<\/p>\n<ol>\n<li>bind()\u9664\u4e86this\u8fd8\u63a5\u6536\u5176\u4ed6\u53c2\u6570\uff0cbind()\u8fd4\u56de\u7684\u51fd\u6570\u4e5f\u63a5\u6536\u53c2\u6570\uff0c\u8fd9\u4e24\u90e8\u5206\u7684\u53c2\u6570\u90fd\u8981\u4f20\u7ed9\u8fd4\u56de\u7684\u51fd\u6570<\/li>\n<li>new\u7684\u4f18\u5148\u7ea7\uff1a\u5982\u679cbind\u7ed1\u5b9a\u540e\u7684\u51fd\u6570\u88abnew\u4e86\uff0c\u90a3\u4e48\u6b64\u65f6this\u6307\u5411\u5c31\u53d1\u751f\u6539\u53d8\u3002\u6b64\u65f6\u7684this\u5c31\u662f\u5f53\u524d\u51fd\u6570\u7684\u5b9e\u4f8b<\/li>\n<li>\u6ca1\u6709\u4fdd\u7559\u539f\u51fd\u6570\u5728\u539f\u578b\u94fe\u4e0a\u7684\u5c5e\u6027\u548c\u65b9\u6cd5<\/li>\n<\/ol>\n<pre><code class=\"language-javascript\" lang=\"javascript\">Function.prototype.myBind = function (thisArg, ...args) {\r\n    var self = this\r\n    \/\/ new\u4f18\u5148\u7ea7\r\n    var fbound = function () {\r\n        self.apply(this instanceof self ? this : thisArg, args.concat(Array.prototype.slice.call(arguments)))\r\n    }\r\n    \/\/ \u7ee7\u627f\u539f\u578b\u4e0a\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\r\n    fbound.prototype = Object.create(self.prototype);\r\n\r\n    return fbound;\r\n}\r\n\r\n\/\/\u6d4b\u8bd5\r\nconst obj = { name: '\u5199\u4ee3\u7801\u50cf\u8521\u5f90\u62bb' }\r\nfunction foo() {\r\n    console.log(this.name)\r\n    console.log(arguments)\r\n}\r\n\r\nfoo.myBind(obj, 'a', 'b', 'c')()    \/\/\u8f93\u51fa\u5199\u4ee3\u7801\u50cf\u8521\u5f90\u62bb ['a', 'b', 'c']\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h2>6. \u624b\u5199\u4e00\u4e2a\u9632\u6296\u51fd\u6570<\/h2>\n<p>\u9632\u6296\u548c\u8282\u6d41\u7684\u6982\u5ff5\u90fd\u6bd4\u8f83\u7b80\u5355\uff0c\u6240\u4ee5\u6211\u4eec\u5c31\u4e0d\u5728\u201c\u9632\u6296\u8282\u6d41\u662f\u4ec0\u4e48\u201d\u8fd9\u4e2a\u95ee\u9898\u4e0a\u6d6a\u8d39\u8fc7\u591a\u7bc7\u5e45\u4e86\uff0c\u7b80\u5355\u70b9\u4e00\u4e0b\uff1a<\/p>\n<blockquote><p>\u9632\u6296\uff0c\u5373<code>\u77ed\u65f6\u95f4\u5185\u5927\u91cf\u89e6\u53d1\u540c\u4e00\u4e8b\u4ef6\uff0c\u53ea\u4f1a\u6267\u884c\u4e00\u6b21\u51fd\u6570<\/code>\uff0c\u5b9e\u73b0\u539f\u7406\u4e3a<code>\u8bbe\u7f6e\u4e00\u4e2a\u5b9a\u65f6\u5668\uff0c\u7ea6\u5b9a\u5728xx\u6beb\u79d2\u540e\u518d\u89e6\u53d1\u4e8b\u4ef6\u5904\u7406\uff0c\u6bcf\u6b21\u89e6\u53d1\u4e8b\u4ef6\u90fd\u4f1a\u91cd\u65b0\u8bbe\u7f6e\u8ba1\u65f6\u5668\uff0c\u76f4\u5230xx\u6beb\u79d2\u5185\u65e0\u7b2c\u4e8c\u6b21\u64cd\u4f5c<\/code>\uff0c\u9632\u6296\u5e38\u7528\u4e8e\u641c\u7d22\u6846\/\u6eda\u52a8\u6761\u7684\u76d1\u542c\u4e8b\u4ef6\u5904\u7406\uff0c\u5982\u679c\u4e0d\u505a\u9632\u6296\uff0c\u6bcf\u8f93\u5165\u4e00\u4e2a\u5b57\/\u6eda\u52a8\u5c4f\u5e55\uff0c\u90fd\u4f1a\u89e6\u53d1\u4e8b\u4ef6\u5904\u7406\uff0c\u9020\u6210\u6027\u80fd\u6d6a\u8d39\u3002<\/p><\/blockquote>\n<pre><code class=\"language-javascript\" lang=\"javascript\">function debounce(func, wait) {\r\n    let timeout = null\r\n    return function() {\r\n        let context = this\r\n        let args = arguments\r\n        if (timeout) clearTimeout(timeout)\r\n        timeout = setTimeout(() =&gt; {\r\n            func.apply(context, args)\r\n        }, wait)\r\n    }\r\n}\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h2>7. \u624b\u5199\u4e00\u4e2a\u8282\u6d41\u51fd\u6570<\/h2>\n<blockquote><p>\u9632\u6296\u662f<code>\u5ef6\u8fdf\u6267\u884c<\/code>\uff0c\u800c\u8282\u6d41\u662f<code>\u95f4\u9694\u6267\u884c<\/code>\uff0c\u51fd\u6570\u8282\u6d41\u5373<code>\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u5c31\u6267\u884c\u4e00\u6b21<\/code>\uff0c\u5b9e\u73b0\u539f\u7406\u4e3a<code>\u8bbe\u7f6e\u4e00\u4e2a\u5b9a\u65f6\u5668\uff0c\u7ea6\u5b9axx\u6beb\u79d2\u540e\u6267\u884c\u4e8b\u4ef6\uff0c\u5982\u679c\u65f6\u95f4\u5230\u4e86\uff0c\u90a3\u4e48\u6267\u884c\u51fd\u6570\u5e76\u91cd\u7f6e\u5b9a\u65f6\u5668<\/code>\uff0c\u548c\u9632\u6296\u7684\u533a\u522b\u5728\u4e8e\uff0c\u9632\u6296\u6bcf\u6b21\u89e6\u53d1\u4e8b\u4ef6\u90fd\u91cd\u7f6e\u5b9a\u65f6\u5668\uff0c\u800c\u8282\u6d41\u5728\u5b9a\u65f6\u5668\u5230\u65f6\u95f4\u540e\u518d\u6e05\u7a7a\u5b9a\u65f6\u5668<\/p><\/blockquote>\n<pre><code class=\"language-javascript\" lang=\"javascript\">function throttle(func, wait) {\r\n    let timeout = null\r\n    return function() {\r\n        let context = this\r\n        let args = arguments\r\n        if (!timeout) {\r\n            timeout = setTimeout(() =&gt; {\r\n                timeout = null\r\n                func.apply(context, args)\r\n            }, wait)\r\n        }\r\n\r\n    }\r\n}\r\n\r\n<\/code><\/pre>\n<blockquote><p>\u5b9e\u73b0\u65b9\u5f0f2\uff1a\u4f7f\u7528\u4e24\u4e2a\u65f6\u95f4\u6233<code>prev\u65e7\u65f6\u95f4\u6233<\/code>\u548c<code>now\u65b0\u65f6\u95f4\u6233<\/code>\uff0c\u6bcf\u6b21\u89e6\u53d1\u4e8b\u4ef6\u90fd\u5224\u65ad\u4e8c\u8005\u7684\u65f6\u95f4\u5dee\uff0c\u5982\u679c\u5230\u8fbe\u89c4\u5b9a\u65f6\u95f4\uff0c\u6267\u884c\u51fd\u6570\u5e76\u91cd\u7f6e\u65e7\u65f6\u95f4\u6233<\/p><\/blockquote>\n<pre><code class=\"language-javascript\" lang=\"javascript\">function throttle(func, wait) {\r\n    var prev = 0;\r\n    return function() {\r\n        let now = Date.now();\r\n        let context = this;\r\n        let args = arguments;\r\n        if (now - prev &gt; wait) {\r\n            func.apply(context, args);\r\n            prev = now;\r\n        }\r\n    }\r\n}\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h2>8. \u6570\u7ec4\u6241\u5e73\u5316<\/h2>\n<blockquote><p>\u5bf9\u4e8e<code>[1, [1,2], [1,2,3]]<\/code>\u8fd9\u6837\u591a\u5c42\u5d4c\u5957\u7684\u6570\u7ec4\uff0c\u6211\u4eec\u5982\u4f55\u5c06\u5176\u6241\u5e73\u5316\u4e3a<code>[1, 1, 2, 1, 2, 3]<\/code>\u8fd9\u6837\u7684\u4e00\u7ef4\u6570\u7ec4\u5462\uff1a<\/p><\/blockquote>\n<p><strong>1.ES6\u7684flat()<\/strong><\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">const arr = [1, [1,2], [1,2,3]]\r\narr.flat(Infinity)  \/\/ [1, 1, 2, 1, 2, 3]\r\n\r\n<\/code><\/pre>\n<p><strong>2.\u5e8f\u5217\u5316\u540e\u6b63\u5219<\/strong><\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">const arr = [1, [1,2], [1,2,3]]\r\nconst str = `[${JSON.stringify(arr).replace(\/(\\[|\\])\/g, '')}]`\r\nJSON.parse(str)   \/\/ [1, 1, 2, 1, 2, 3]\r\n\r\n<\/code><\/pre>\n<p><strong>3.\u9012\u5f52<\/strong><br \/>\n\u5bf9\u4e8e\u6811\u72b6\u7ed3\u6784\u7684\u6570\u636e\uff0c\u6700\u76f4\u63a5\u7684\u5904\u7406\u65b9\u5f0f\u5c31\u662f\u9012\u5f52<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">const arr = [1, [1,2], [1,2,3]]\r\nfunction flat(arr) {\r\n  let result = []\r\n  for (const item of arr) {\r\n    item instanceof Array ? result = result.concat(flat(item)) : result.push(item)\r\n  }\r\n  return result\r\n}\r\n\r\nflat(arr) \/\/ [1, 1, 2, 1, 2, 3]\r\n\r\n<\/code><\/pre>\n<p><strong>4.reduce()\u9012\u5f52<\/strong><\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">const arr = [1, [1,2], [1,2,3]]\r\nfunction flat(arr) {\r\n  return arr.reduce((prev, cur) =&gt; {\r\n    return prev.concat(cur instanceof Array ? flat(cur) : cur)\r\n  }, [])\r\n}\r\n\r\nflat(arr)  \/\/ [1, 1, 2, 1, 2, 3]\r\n\r\n<\/code><\/pre>\n<p><strong>5.\u8fed\u4ee3+\u5c55\u5f00\u8fd0\u7b97\u7b26<\/strong><\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">\/\/ \u6bcf\u6b21while\u90fd\u4f1a\u5408\u5e76\u4e00\u5c42\u7684\u5143\u7d20\uff0c\u8fd9\u91cc\u7b2c\u4e00\u6b21\u5408\u5e76\u7ed3\u679c\u4e3a[1, 1, 2, 1, 2, 3, [4,4,4]]\r\n\/\/ \u7136\u540earr.some\u5224\u5b9a\u6570\u7ec4\u4e2d\u662f\u5426\u5b58\u5728\u6570\u7ec4\uff0c\u56e0\u4e3a\u5b58\u5728[4,4,4]\uff0c\u7ee7\u7eed\u8fdb\u5165\u7b2c\u4e8c\u6b21\u5faa\u73af\u8fdb\u884c\u5408\u5e76\r\nlet arr = [1, [1,2], [1,2,3,[4,4,4]]]\r\nwhile (arr.some(Array.isArray)) {\r\n  arr = [].concat(...arr);\r\n}\r\n\r\nconsole.log(arr)  \/\/ [1, 1, 2, 1, 2, 3, 4, 4, 4]\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h2>9. \u624b\u5199\u4e00\u4e2aPromise<\/h2>\n<blockquote><p>\u5b9e\u73b0\u4e00\u4e2a\u7b26\u5408\u89c4\u8303\u7684Promise\u7bc7\u5e45\u6bd4\u8f83\u957f\uff0c\u5efa\u8bae\u9605\u8bfb\u7b14\u8005\u4e0a\u4e00\u7bc7\u6587\u7ae0\uff1a<a href=\"https:\/\/juejin.im\/post\/5e3b9ae26fb9a07ca714a5cc\">\u5f02\u6b65\u7f16\u7a0b\u4e8c\u4e09\u4e8b | Promise\/async\/Generator\u5b9e\u73b0\u539f\u7406\u89e3\u6790 | 9k\u5b57<\/a><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h1>JS\u9762\u5411\u5bf9\u8c61<\/h1>\n<p>\u5728JS\u4e2d\u4e00\u5207\u7686\u5bf9\u8c61\uff0c\u4f46JS\u5e76\u4e0d\u662f\u4e00\u79cd\u771f\u6b63\u7684\u9762\u5411\u5bf9\u8c61(OOP)\u7684\u8bed\u8a00\uff0c\u56e0\u4e3a\u5b83\u7f3a\u5c11<code>\u7c7b(class)<\/code>\u7684\u6982\u5ff5\u3002\u867d\u7136ES6\u5f15\u5165\u4e86<code>class<\/code>\u548c<code>extends<\/code>\uff0c\u4f7f\u6211\u4eec\u80fd\u591f\u8f7b\u6613\u5730\u5b9e\u73b0\u7c7b\u548c\u7ee7\u627f\u3002\u4f46JS\u5e76\u4e0d\u5b58\u5728\u771f\u5b9e\u7684\u7c7b\uff0cJS\u7684\u7c7b\u662f\u901a\u8fc7\u51fd\u6570\u4ee5\u53ca\u539f\u578b\u94fe\u673a\u5236\u6a21\u62df\u7684\uff0c\u672c\u5c0f\u8282\u7684\u5c31\u6765\u63a2\u7a76\u5982\u4f55\u5728ES5\u73af\u5883\u4e0b\u5229\u7528\u51fd\u6570\u548c\u539f\u578b\u94fe\u5b9e\u73b0JS\u9762\u5411\u5bf9\u8c61\u7684\u7279\u6027<\/p>\n<p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u56de\u987e\u4e00\u4e0b\u539f\u578b\u94fe\u7684\u77e5\u8bc6\uff0c\u540e\u7eed<code>new<\/code>\u548c<code>\u7ee7\u627f<\/code>\u7b49\u5b9e\u73b0\u90fd\u662f\u57fa\u4e8e\u539f\u578b\u94fe\u673a\u5236\u3002\u5f88\u591a\u4ecb\u7ecd\u539f\u578b\u94fe\u7684\u8d44\u6599\u90fd\u80fd\u5199\u4e0a\u6d0b\u6d0b\u6d12\u6d12\u51e0\u5343\u5b57\uff0c\u4f46\u6211\u89c9\u5f97\u8bfb\u8005\u4eec\u4e0d\u9700\u8981\u628a\u539f\u578b\u94fe\u60f3\u592a\u590d\u6742\uff0c\u5bb9\u6613\u628a\u81ea\u5df1\u7ed5\u8fdb\u53bb\uff0c\u5176\u5b9e\u5728\u6211\u770b\u6765\uff0c\u539f\u578b\u94fe\u7684\u6838\u5fc3\u53ea\u9700\u8981\u8bb0\u4f4f\u4e09\u70b9\uff1a<\/p>\n<ol>\n<li>\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u6709<code>__proto__\u5c5e\u6027<\/code>\uff0c\u8be5\u5c5e\u6027\u6307\u5411\u5176\u539f\u578b\u5bf9\u8c61\uff0c\u5728\u8c03\u7528\u5b9e\u4f8b\u7684\u65b9\u6cd5\u548c\u5c5e\u6027\u65f6\uff0c\u5982\u679c\u5728\u5b9e\u4f8b\u5bf9\u8c61\u4e0a\u627e\u4e0d\u5230\uff0c\u5c31\u4f1a\u5f80\u539f\u578b\u5bf9\u8c61\u4e0a\u627e<\/li>\n<li>\u6784\u9020\u51fd\u6570\u7684<code>prototype\u5c5e\u6027<\/code>\u4e5f\u6307\u5411\u5b9e\u4f8b\u7684\u539f\u578b\u5bf9\u8c61<\/li>\n<li>\u539f\u578b\u5bf9\u8c61\u7684<code>constructor\u5c5e\u6027<\/code>\u6307\u5411\u6784\u9020\u51fd\u6570<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>1. \u6a21\u62df\u5b9e\u73b0new<\/h2>\n<p>\u9996\u5148\u6211\u4eec\u8981\u77e5\u9053<code>new<\/code>\u505a\u4e86\u4ec0\u4e48<\/p>\n<ol>\n<li><strong>\u521b\u5efa\u4e00\u4e2a\u65b0\u5bf9\u8c61\uff0c\u5e76\u7ee7\u627f\u5176\u6784\u9020\u51fd\u6570\u7684<code>prototype<\/code><\/strong>\uff0c\u8fd9\u4e00\u6b65\u662f\u4e3a\u4e86\u7ee7\u627f\u6784\u9020\u51fd\u6570\u539f\u578b\u4e0a\u7684\u5c5e\u6027\u548c\u65b9\u6cd5<\/li>\n<li><strong>\u6267\u884c\u6784\u9020\u51fd\u6570\uff0c\u65b9\u6cd5\u5185\u7684<code>this<\/code>\u88ab\u6307\u5b9a\u4e3a\u8be5\u65b0\u5b9e\u4f8b<\/strong>\uff0c\u8fd9\u4e00\u6b65\u662f\u4e3a\u4e86\u6267\u884c\u6784\u9020\u51fd\u6570\u5185\u7684\u8d4b\u503c\u64cd\u4f5c<\/li>\n<li><strong>\u8fd4\u56de\u65b0\u5b9e\u4f8b<\/strong>\uff08\u89c4\u8303\u89c4\u5b9a\uff0c\u5982\u679c\u6784\u9020\u65b9\u6cd5\u8fd4\u56de\u4e86\u4e00\u4e2a\u5bf9\u8c61\uff0c\u90a3\u4e48\u8fd4\u56de\u8be5\u5bf9\u8c61\uff0c\u5426\u5219\u8fd4\u56de\u7b2c\u4e00\u6b65\u521b\u5efa\u7684\u65b0\u5bf9\u8c61\uff09<\/li>\n<\/ol>\n<pre><code class=\"language-javascript\" lang=\"javascript\">\/\/ new\u662f\u5173\u952e\u5b57,\u8fd9\u91cc\u6211\u4eec\u7528\u51fd\u6570\u6765\u6a21\u62df,new Foo(args) &lt;=&gt; myNew(Foo, args)\r\nfunction myNew(foo, ...args) {\r\n  \/\/ \u521b\u5efa\u65b0\u5bf9\u8c61,\u5e76\u7ee7\u627f\u6784\u9020\u65b9\u6cd5\u7684prototype\u5c5e\u6027, \u8fd9\u4e00\u6b65\u662f\u4e3a\u4e86\u628aobj\u6302\u539f\u578b\u94fe\u4e0a, \u76f8\u5f53\u4e8eobj.__proto__ = Foo.prototype\r\n  let obj = Object.create(foo.prototype)  \r\n  \r\n  \/\/ \u6267\u884c\u6784\u9020\u65b9\u6cd5, \u5e76\u4e3a\u5176\u7ed1\u5b9a\u65b0this, \u8fd9\u4e00\u6b65\u662f\u4e3a\u4e86\u8ba9\u6784\u9020\u65b9\u6cd5\u80fd\u8fdb\u884cthis.name = name\u4e4b\u7c7b\u7684\u64cd\u4f5c, args\u662f\u6784\u9020\u65b9\u6cd5\u7684\u5165\u53c2, \u56e0\u4e3a\u8fd9\u91cc\u7528myNew\u6a21\u62df, \u6240\u4ee5\u5165\u53c2\u4ecemyNew\u4f20\u5165\r\n  let result = foo.apply(obj, args)\r\n\r\n  \/\/ \u5982\u679c\u6784\u9020\u65b9\u6cd5\u5df2\u7ecfreturn\u4e86\u4e00\u4e2a\u5bf9\u8c61, \u90a3\u4e48\u5c31\u8fd4\u56de\u8be5\u5bf9\u8c61, \u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u6784\u9020\u65b9\u6cd5\u4e0d\u4f1a\u8fd4\u56de\u65b0\u5b9e\u4f8b\uff0c\u4f46\u4f7f\u7528\u8005\u53ef\u4ee5\u9009\u62e9\u8fd4\u56de\u65b0\u5b9e\u4f8b\u6765\u8986\u76d6new\u521b\u5efa\u7684\u5bf9\u8c61 \u5426\u5219\u8fd4\u56demyNew\u521b\u5efa\u7684\u65b0\u5bf9\u8c61\r\n  return typeof result === 'object' &amp;&amp; result !== null ? result : obj\r\n}\r\n\r\nfunction Foo(name) {\r\n  this.name = name\r\n}\r\nconst newObj = myNew(Foo, 'zhangsan')\r\nconsole.log(newObj)                 \/\/ Foo {name: \"zhangsan\"}\r\nconsole.log(newObj instanceof Foo)  \/\/ true\r\n\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h2>2. ES5\u5982\u4f55\u5b9e\u73b0\u7ee7\u627f<\/h2>\n<p>\u8bf4\u5230\u7ee7\u627f\uff0c\u6700\u5bb9\u6613\u60f3\u5230\u7684\u662fES6\u7684<code>extends<\/code>\uff0c\u5f53\u7136\u5982\u679c\u53ea\u56de\u7b54\u8fd9\u4e2a\u80af\u5b9a\u4e0d\u5408\u683c\uff0c\u6211\u4eec\u8981\u4ece\u51fd\u6570\u548c\u539f\u578b\u94fe\u7684\u89d2\u5ea6\u4e0a\u5b9e\u73b0\u7ee7\u627f\uff0c\u4e0b\u9762\u6211\u4eec\u4e00\u6b65\u6b65\u5730\u3001\u9012\u8fdb\u5730\u5b9e\u73b0\u4e00\u4e2a\u5408\u683c\u7684\u7ee7\u627f<\/p>\n<h3>\u4e00. \u539f\u578b\u94fe\u7ee7\u627f<\/h3>\n<p>\u539f\u578b\u94fe\u7ee7\u627f\u7684\u539f\u7406\u5f88\u7b80\u5355\uff0c\u76f4\u63a5\u8ba9\u5b50\u7c7b\u7684\u539f\u578b\u5bf9\u8c61\u6307\u5411\u7236\u7c7b\u5b9e\u4f8b\uff0c\u5f53\u5b50\u7c7b\u5b9e\u4f8b\u627e\u4e0d\u5230\u5bf9\u5e94\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u65f6\uff0c\u5c31\u4f1a\u5f80\u5b83\u7684\u539f\u578b\u5bf9\u8c61\uff0c\u4e5f\u5c31\u662f\u7236\u7c7b\u5b9e\u4f8b\u4e0a\u627e\uff0c\u4ece\u800c\u5b9e\u73b0\u5bf9\u7236\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u7684\u7ee7\u627f<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">\/\/ \u7236\u7c7b\r\nfunction Parent() {\r\n    this.name = '\u5199\u4ee3\u7801\u50cf\u8521\u5f90\u62bb'\r\n}\r\n\/\/ \u7236\u7c7b\u7684\u539f\u578b\u65b9\u6cd5\r\nParent.prototype.getName = function() {\r\n    return this.name\r\n}\r\n\/\/ \u5b50\u7c7b\r\nfunction Child() {}\r\n\r\n\/\/ \u8ba9\u5b50\u7c7b\u7684\u539f\u578b\u5bf9\u8c61\u6307\u5411\u7236\u7c7b\u5b9e\u4f8b, \u8fd9\u6837\u4e00\u6765\u5728Child\u5b9e\u4f8b\u4e2d\u627e\u4e0d\u5230\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u5c31\u4f1a\u5230\u539f\u578b\u5bf9\u8c61(\u7236\u7c7b\u5b9e\u4f8b)\u4e0a\u5bfb\u627e\r\nChild.prototype = new Parent()\r\nChild.prototype.constructor = Child \/\/ \u6839\u636e\u539f\u578b\u94fe\u7684\u89c4\u5219,\u987a\u4fbf\u7ed1\u5b9a\u4e00\u4e0bconstructor, \u8fd9\u4e00\u6b65\u4e0d\u5f71\u54cd\u7ee7\u627f, \u53ea\u662f\u5728\u7528\u5230constructor\u65f6\u4f1a\u9700\u8981\r\n\r\n\/\/ \u7136\u540eChild\u5b9e\u4f8b\u5c31\u80fd\u8bbf\u95ee\u5230\u7236\u7c7b\u53ca\u5176\u539f\u578b\u4e0a\u7684name\u5c5e\u6027\u548cgetName()\u65b9\u6cd5\r\nconst child = new Child()\r\nchild.name          \/\/ '\u5199\u4ee3\u7801\u50cf\u8521\u5f90\u62bb'\r\nchild.getName()     \/\/ '\u5199\u4ee3\u7801\u50cf\u8521\u5f90\u62bb'\r\n\r\n<\/code><\/pre>\n<blockquote><p>\u539f\u578b\u7ee7\u627f\u7684\u7f3a\u70b9:<\/p><\/blockquote>\n<ol>\n<li>\u7531\u4e8e\u6240\u6709Child\u5b9e\u4f8b\u539f\u578b\u90fd\u6307\u5411\u540c\u4e00\u4e2aParent\u5b9e\u4f8b, \u56e0\u6b64\u5bf9\u67d0\u4e2aChild\u5b9e\u4f8b\u7684\u7236\u7c7b\u5f15\u7528\u7c7b\u578b\u53d8\u91cf\u4fee\u6539\u4f1a\u5f71\u54cd\u6240\u6709\u7684Child\u5b9e\u4f8b<\/li>\n<li>\u5728\u521b\u5efa\u5b50\u7c7b\u5b9e\u4f8b\u65f6\u65e0\u6cd5\u5411\u7236\u7c7b\u6784\u9020\u4f20\u53c2, \u5373\u6ca1\u6709\u5b9e\u73b0<code>super()<\/code>\u7684\u529f\u80fd<\/li>\n<\/ol>\n<pre><code class=\"language-javascript\" lang=\"javascript\">\/\/ \u793a\u4f8b:\r\nfunction Parent() {\r\n    this.name = ['\u5199\u4ee3\u7801\u50cf\u8521\u5f90\u62bb'] \r\n}\r\nParent.prototype.getName = function() {\r\n    return this.name\r\n}\r\nfunction Child() {}\r\n\r\nChild.prototype = new Parent()\r\nChild.prototype.constructor = Child \r\n\r\n\/\/ \u6d4b\u8bd5\r\nconst child1 = new Child()\r\nconst child2 = new Child()\r\nchild1.name[0] = 'foo'\r\nconsole.log(child1.name)          \/\/ ['foo']\r\nconsole.log(child2.name)          \/\/ ['foo'] (\u9884\u671f\u662f['\u5199\u4ee3\u7801\u50cf\u8521\u5f90\u62bb'], \u5bf9child1.name\u7684\u4fee\u6539\u5f15\u8d77\u4e86\u6240\u6709child\u5b9e\u4f8b\u7684\u53d8\u5316)\r\n\r\n<\/code><\/pre>\n<h3>\u4e8c. \u6784\u9020\u51fd\u6570\u7ee7\u627f<\/h3>\n<p>\u6784\u9020\u51fd\u6570\u7ee7\u627f\uff0c\u5373\u5728\u5b50\u7c7b\u7684\u6784\u9020\u51fd\u6570\u4e2d\u6267\u884c\u7236\u7c7b\u7684\u6784\u9020\u51fd\u6570\uff0c\u5e76\u4e3a\u5176\u7ed1\u5b9a\u5b50\u7c7b\u7684<code>this<\/code>\uff0c\u8ba9\u7236\u7c7b\u7684\u6784\u9020\u51fd\u6570\u628a\u6210\u5458\u5c5e\u6027\u548c\u65b9\u6cd5\u90fd\u6302\u5230<code>\u5b50\u7c7b\u7684this<\/code>\u4e0a\u53bb\uff0c\u8fd9\u6837\u65e2\u80fd\u907f\u514d\u5b9e\u4f8b\u4e4b\u95f4\u5171\u4eab\u4e00\u4e2a\u539f\u578b\u5b9e\u4f8b\uff0c\u53c8\u80fd\u5411\u7236\u7c7b\u6784\u9020\u65b9\u6cd5\u4f20\u53c2<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">function Parent(name) {\r\n    this.name = [name]\r\n}\r\nParent.prototype.getName = function() {\r\n    return this.name\r\n}\r\nfunction Child() {\r\n    Parent.call(this, 'zhangsan')   \/\/ \u6267\u884c\u7236\u7c7b\u6784\u9020\u65b9\u6cd5\u5e76\u7ed1\u5b9a\u5b50\u7c7b\u7684this, \u4f7f\u5f97\u7236\u7c7b\u4e2d\u7684\u5c5e\u6027\u80fd\u591f\u8d4b\u5230\u5b50\u7c7b\u7684this\u4e0a\r\n}\r\n\r\n\/\/\u6d4b\u8bd5\r\nconst child1 = new Child()\r\nconst child2 = new Child()\r\nchild1.name[0] = 'foo'\r\nconsole.log(child1.name)          \/\/ ['foo']\r\nconsole.log(child2.name)          \/\/ ['zhangsan']\r\nchild2.getName()                  \/\/ \u62a5\u9519,\u627e\u4e0d\u5230getName(), \u6784\u9020\u51fd\u6570\u7ee7\u627f\u7684\u65b9\u5f0f\u7ee7\u627f\u4e0d\u5230\u7236\u7c7b\u539f\u578b\u4e0a\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\r\n\r\n<\/code><\/pre>\n<blockquote><p>\u6784\u9020\u51fd\u6570\u7ee7\u627f\u7684\u7f3a\u70b9:<\/p><\/blockquote>\n<ol>\n<li>\u7ee7\u627f\u4e0d\u5230\u7236\u7c7b\u539f\u578b\u4e0a\u7684\u5c5e\u6027\u548c\u65b9\u6cd5<\/li>\n<\/ol>\n<h3>\u4e09. \u7ec4\u5408\u5f0f\u7ee7\u627f<\/h3>\n<p>\u65e2\u7136\u539f\u578b\u94fe\u7ee7\u627f\u548c\u6784\u9020\u51fd\u6570\u7ee7\u627f\u5404\u6709\u4e92\u8865\u7684\u4f18\u7f3a\u70b9, \u90a3\u4e48\u6211\u4eec\u4e3a\u4ec0\u4e48\u4e0d\u7ec4\u5408\u8d77\u6765\u4f7f\u7528\u5462, \u6240\u4ee5\u5c31\u6709\u4e86\u7efc\u5408\u4e8c\u8005\u7684\u7ec4\u5408\u5f0f\u7ee7\u627f<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">function Parent(name) {\r\n    this.name = [name]\r\n}\r\nParent.prototype.getName = function() {\r\n    return this.name\r\n}\r\nfunction Child() {\r\n    \/\/ \u6784\u9020\u51fd\u6570\u7ee7\u627f\r\n    Parent.call(this, 'zhangsan') \r\n}\r\n\/\/\u539f\u578b\u94fe\u7ee7\u627f\r\nChild.prototype = new Parent()\r\nChild.prototype.constructor = Child\r\n\r\n\/\/\u6d4b\u8bd5\r\nconst child1 = new Child()\r\nconst child2 = new Child()\r\nchild1.name[0] = 'foo'\r\nconsole.log(child1.name)          \/\/ ['foo']\r\nconsole.log(child2.name)          \/\/ ['zhangsan']\r\nchild2.getName()                  \/\/ ['zhangsan']\r\n\r\n<\/code><\/pre>\n<blockquote><p>\u7ec4\u5408\u5f0f\u7ee7\u627f\u7684\u7f3a\u70b9:<\/p><\/blockquote>\n<ol>\n<li>\u6bcf\u6b21\u521b\u5efa\u5b50\u7c7b\u5b9e\u4f8b\u90fd\u6267\u884c\u4e86\u4e24\u6b21\u6784\u9020\u51fd\u6570(<code>Parent.call()<\/code>\u548c<code>new Parent()<\/code>)\uff0c\u867d\u7136\u8fd9\u5e76\u4e0d\u5f71\u54cd\u5bf9\u7236\u7c7b\u7684\u7ee7\u627f\uff0c\u4f46\u5b50\u7c7b\u521b\u5efa\u5b9e\u4f8b\u65f6\uff0c\u539f\u578b\u4e2d\u4f1a\u5b58\u5728\u4e24\u4efd\u76f8\u540c\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u8fd9\u5e76\u4e0d\u4f18\u96c5<\/li>\n<\/ol>\n<h3>\u56db. \u5bc4\u751f\u5f0f\u7ec4\u5408\u7ee7\u627f<\/h3>\n<p>\u4e3a\u4e86\u89e3\u51b3\u6784\u9020\u51fd\u6570\u88ab\u6267\u884c\u4e24\u6b21\u7684\u95ee\u9898, \u6211\u4eec\u5c06<code>\u6307\u5411\u7236\u7c7b\u5b9e\u4f8b<\/code>\u6539\u4e3a<code>\u6307\u5411\u7236\u7c7b\u539f\u578b<\/code>, \u51cf\u53bb\u4e00\u6b21\u6784\u9020\u51fd\u6570\u7684\u6267\u884c<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">function Parent(name) {\r\n    this.name = [name]\r\n}\r\nParent.prototype.getName = function() {\r\n    return this.name\r\n}\r\nfunction Child() {\r\n    \/\/ \u6784\u9020\u51fd\u6570\u7ee7\u627f\r\n    Parent.call(this, 'zhangsan') \r\n}\r\n\/\/\u539f\u578b\u94fe\u7ee7\u627f\r\n\/\/ Child.prototype = new Parent()\r\nChild.prototype = Parent.prototype  \/\/\u5c06`\u6307\u5411\u7236\u7c7b\u5b9e\u4f8b`\u6539\u4e3a`\u6307\u5411\u7236\u7c7b\u539f\u578b`\r\nChild.prototype.constructor = Child\r\n\r\n\/\/\u6d4b\u8bd5\r\nconst child1 = new Child()\r\nconst child2 = new Child()\r\nchild1.name[0] = 'foo'\r\nconsole.log(child1.name)          \/\/ ['foo']\r\nconsole.log(child2.name)          \/\/ ['zhangsan']\r\nchild2.getName()                  \/\/ ['zhangsan']\r\n\r\n<\/code><\/pre>\n<p>\u4f46\u8fd9\u79cd\u65b9\u5f0f\u5b58\u5728\u4e00\u4e2a\u95ee\u9898\uff0c\u7531\u4e8e\u5b50\u7c7b\u539f\u578b\u548c\u7236\u7c7b\u539f\u578b\u6307\u5411\u540c\u4e00\u4e2a\u5bf9\u8c61\uff0c\u6211\u4eec\u5bf9\u5b50\u7c7b\u539f\u578b\u7684\u64cd\u4f5c\u4f1a\u5f71\u54cd\u5230\u7236\u7c7b\u539f\u578b\uff0c\u4f8b\u5982\u7ed9<code>Child.prototype<\/code>\u589e\u52a0\u4e00\u4e2agetName()\u65b9\u6cd5\uff0c\u90a3\u4e48\u4f1a\u5bfc\u81f4<code>Parent.prototype<\/code>\u4e5f\u589e\u52a0\u6216\u88ab\u8986\u76d6\u4e00\u4e2agetName()\u65b9\u6cd5\uff0c\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u7ed9<code>Parent.prototype<\/code>\u505a\u4e00\u4e2a\u6d45\u62f7\u8d1d<\/p>\n<pre><code class=\"language-javascript\" lang=\"javascript\">function Parent(name) {\r\n    this.name = [name]\r\n}\r\nParent.prototype.getName = function() {\r\n    return this.name\r\n}\r\nfunction Child() {\r\n    \/\/ \u6784\u9020\u51fd\u6570\u7ee7\u627f\r\n    Parent.call(this, 'zhangsan') \r\n}\r\n\/\/\u539f\u578b\u94fe\u7ee7\u627f\r\n\/\/ Child.prototype = new Parent()\r\nChild.prototype = Object.create(Parent.prototype)  \/\/\u5c06`\u6307\u5411\u7236\u7c7b\u5b9e\u4f8b`\u6539\u4e3a`\u6307\u5411\u7236\u7c7b\u539f\u578b`\r\nChild.prototype.constructor = Child\r\n\r\n\/\/\u6d4b\u8bd5\r\nconst child = new Child()\r\nconst parent = new Parent()\r\nchild.getName()                  \/\/ ['zhangsan']\r\nparent.getName()                 \/\/ \u62a5\u9519, \u627e\u4e0d\u5230getName()\r\n\r\n<\/code><\/pre>\n<p>\u5230\u8fd9\u91cc\u6211\u4eec\u5c31\u5b8c\u6210\u4e86ES5\u73af\u5883\u4e0b\u7684\u7ee7\u627f\u7684\u5b9e\u73b0\uff0c\u8fd9\u79cd\u7ee7\u627f\u65b9\u5f0f\u79f0\u4e3a<code>\u5bc4\u751f\u7ec4\u5408\u5f0f\u7ee7\u627f<\/code>\uff0c\u662f\u76ee\u524d\u6700\u6210\u719f\u7684\u7ee7\u627f\u65b9\u5f0f\uff0cbabel\u5bf9ES6\u7ee7\u627f\u7684\u8f6c\u5316\u4e5f\u662f\u4f7f\u7528\u4e86\u5bc4\u751f\u7ec4\u5408\u5f0f\u7ee7\u627f<\/p>\n<p>\u6211\u4eec\u56de\u987e\u4e00\u4e0b\u5b9e\u73b0\u8fc7\u7a0b\uff1a<br \/>\n\u4e00\u5f00\u59cb\u6700\u5bb9\u6613\u60f3\u5230\u7684\u662f<code>\u539f\u578b\u94fe\u7ee7\u627f<\/code>\uff0c\u901a\u8fc7\u628a\u5b50\u7c7b\u5b9e\u4f8b\u7684\u539f\u578b\u6307\u5411\u7236\u7c7b\u5b9e\u4f8b\u6765\u7ee7\u627f\u7236\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u4f46\u539f\u578b\u94fe\u7ee7\u627f\u7684\u7f3a\u9677\u5728\u4e8e<code>\u5bf9\u5b50\u7c7b\u5b9e\u4f8b\u7ee7\u627f\u7684\u5f15\u7528\u7c7b\u578b\u7684\u4fee\u6539\u4f1a\u5f71\u54cd\u5230\u6240\u6709\u7684\u5b9e\u4f8b\u5bf9\u8c61<\/code>\u4ee5\u53ca<code>\u65e0\u6cd5\u5411\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u4f20\u53c2<\/code>\u3002<br \/>\n\u56e0\u6b64\u6211\u4eec\u5f15\u5165\u4e86<code>\u6784\u9020\u51fd\u6570\u7ee7\u627f<\/code>, \u901a\u8fc7\u5728\u5b50\u7c7b\u6784\u9020\u51fd\u6570\u4e2d\u8c03\u7528\u7236\u7c7b\u6784\u9020\u51fd\u6570\u5e76\u4f20\u5165\u5b50\u7c7bthis\u6765\u83b7\u53d6\u7236\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u4f46\u6784\u9020\u51fd\u6570\u7ee7\u627f\u4e5f\u5b58\u5728\u7f3a\u9677\uff0c\u6784\u9020\u51fd\u6570\u7ee7\u627f<code>\u4e0d\u80fd\u7ee7\u627f\u5230\u7236\u7c7b\u539f\u578b\u94fe\u4e0a\u7684\u5c5e\u6027\u548c\u65b9\u6cd5<\/code>\u3002<br \/>\n\u6240\u4ee5\u6211\u4eec\u7efc\u5408\u4e86\u4e24\u79cd\u7ee7\u627f\u7684\u4f18\u70b9\uff0c\u63d0\u51fa\u4e86<code>\u7ec4\u5408\u5f0f\u7ee7\u627f<\/code>\uff0c\u4f46\u7ec4\u5408\u5f0f\u7ee7\u627f\u4e5f\u5f15\u5165\u4e86\u65b0\u7684\u95ee\u9898\uff0c\u5b83<code>\u6bcf\u6b21\u521b\u5efa\u5b50\u7c7b\u5b9e\u4f8b\u90fd\u6267\u884c\u4e86\u4e24\u6b21\u7236\u7c7b\u6784\u9020\u65b9\u6cd5<\/code>\uff0c\u6211\u4eec\u901a\u8fc7\u5c06<code>\u5b50\u7c7b\u539f\u578b\u6307\u5411\u7236\u7c7b\u5b9e\u4f8b<\/code>\u6539\u4e3a<code>\u5b50\u7c7b\u539f\u578b\u6307\u5411\u7236\u7c7b\u539f\u578b\u7684\u6d45\u62f7\u8d1d<\/code>\u6765\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\uff0c\u4e5f\u5c31\u662f\u6700\u7ec8\u5b9e\u73b0 \u2014\u2014 <code>\u5bc4\u751f\u7ec4\u5408\u5f0f\u7ee7\u627f<\/code><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h1>V8\u5f15\u64ce\u673a\u5236<\/h1>\n<h2>1. V8\u5982\u4f55\u6267\u884c\u4e00\u6bb5JS\u4ee3\u7801<\/h2>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/1701324268cca319.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2736\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/1701324268cca319.png\" alt=\"1701324268cca319\" width=\"960\" height=\"540\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<ol>\n<li><strong>\u9884\u89e3\u6790<\/strong>\uff1a\u68c0\u67e5\u8bed\u6cd5\u9519\u8bef\u4f46\u4e0d\u751f\u6210AST<\/li>\n<li><strong>\u751f\u6210AST<\/strong>\uff1a\u7ecf\u8fc7\u8bcd\u6cd5\/\u8bed\u6cd5\u5206\u6790\uff0c\u751f\u6210\u62bd\u8c61\u8bed\u6cd5\u6811<\/li>\n<li><strong>\u751f\u6210\u5b57\u8282\u7801<\/strong>\uff1a\u57fa\u7ebf\u7f16\u8bd1\u5668(Ignition)\u5c06AST\u8f6c\u6362\u6210\u5b57\u8282\u7801<\/li>\n<li><strong>\u751f\u6210\u673a\u5668\u7801<\/strong>\uff1a\u4f18\u5316\u7f16\u8bd1\u5668(Turbofan)\u5c06\u5b57\u8282\u7801\u8f6c\u6362\u6210\u4f18\u5316\u8fc7\u7684\u673a\u5668\u7801\uff0c\u6b64\u5916\u5728\u9010\u884c\u6267\u884c\u5b57\u8282\u7801\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u4e00\u6bb5\u4ee3\u7801\u7ecf\u5e38\u88ab\u6267\u884c\uff0c\u90a3\u4e48V8\u4f1a\u5c06\u8fd9\u6bb5\u4ee3\u7801\u76f4\u63a5\u8f6c\u6362\u6210\u673a\u5668\u7801\u4fdd\u5b58\u8d77\u6765\uff0c\u4e0b\u4e00\u6b21\u6267\u884c\u5c31\u4e0d\u5fc5\u7ecf\u8fc7\u5b57\u8282\u7801\uff0c\u4f18\u5316\u4e86\u6267\u884c\u901f\u5ea6<\/li>\n<\/ol>\n<p>\u4e0a\u9762\u51e0\u70b9\u53ea\u662fV8\u6267\u884c\u673a\u5236\u7684\u6781\u7b80\u603b\u7ed3\uff0c\u5efa\u8bae\u9605\u8bfb\u53c2\u8003\u8d44\u6599\uff1a<\/p>\n<blockquote><p>1.<a href=\"https:\/\/juejin.im\/post\/5dc4d823f265da4d4c202d3b\">V8 \u662f\u600e\u4e48\u8dd1\u8d77\u6765\u7684 \u2014\u2014 V8 \u7684 JavaScript \u6267\u884c\u7ba1\u9053<\/a><br \/>\n2.<a href=\"https:\/\/juejin.im\/post\/5df1ed1f6fb9a015fd69b78d\">JavaScript \u5f15\u64ce V8 \u6267\u884c\u6d41\u7a0b\u6982\u8ff0<\/a><\/p><\/blockquote>\n<h2>2. \u4ecb\u7ecd\u4e00\u4e0b\u5f15\u7528\u8ba1\u6570\u548c\u6807\u8bb0\u6e05\u9664<\/h2>\n<ul>\n<li><strong>\u5f15\u7528\u8ba1\u6570<\/strong>\uff1a\u7ed9\u4e00\u4e2a\u53d8\u91cf\u8d4b\u503c\u5f15\u7528\u7c7b\u578b\uff0c\u5219\u8be5\u5bf9\u8c61\u7684\u5f15\u7528\u6b21\u6570+1\uff0c\u5982\u679c\u8fd9\u4e2a\u53d8\u91cf\u53d8\u6210\u4e86\u5176\u4ed6\u503c\uff0c\u90a3\u4e48\u8be5\u5bf9\u8c61\u7684\u5f15\u7528\u6b21\u6570-1\uff0c\u5783\u573e\u56de\u6536\u5668\u4f1a\u56de\u6536\u5f15\u7528\u6b21\u6570\u4e3a0\u7684\u5bf9\u8c61\u3002\u4f46\u662f\u5f53\u5bf9\u8c61\u5faa\u73af\u5f15\u7528\u65f6\uff0c\u4f1a\u5bfc\u81f4\u5f15\u7528\u6b21\u6570\u6c38\u8fdc\u65e0\u6cd5\u5f52\u96f6\uff0c\u9020\u6210\u5185\u5b58\u65e0\u6cd5\u91ca\u653e\u3002<\/li>\n<li><strong>\u6807\u8bb0\u6e05\u9664<\/strong>\uff1a\u5783\u573e\u6536\u96c6\u5668\u5148\u7ed9\u5185\u5b58\u4e2d\u6240\u6709\u5bf9\u8c61\u52a0\u4e0a\u6807\u8bb0\uff0c\u7136\u540e\u4ece\u6839\u8282\u70b9\u5f00\u59cb\u904d\u5386\uff0c\u53bb\u6389\u88ab\u5f15\u7528\u7684\u5bf9\u8c61\u548c\u8fd0\u884c\u73af\u5883\u4e2d\u5bf9\u8c61\u7684\u6807\u8bb0\uff0c\u5269\u4e0b\u7684\u88ab\u6807\u8bb0\u7684\u5bf9\u8c61\u5c31\u662f\u65e0\u6cd5\u8bbf\u95ee\u7684\u7b49\u5f85\u56de\u6536\u7684\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<h2>3. V8\u5982\u4f55\u8fdb\u884c\u5783\u573e\u56de\u6536<\/h2>\n<p>JS\u5f15\u64ce\u4e2d\u5bf9\u53d8\u91cf\u7684\u5b58\u50a8\u4e3b\u8981\u6709\u4e24\u79cd\u4f4d\u7f6e\uff0c\u6808\u5185\u5b58\u548c\u5806\u5185\u5b58\uff0c\u6808\u5185\u5b58\u5b58\u50a8\u57fa\u672c\u7c7b\u578b\u6570\u636e\u4ee5\u53ca\u5f15\u7528\u7c7b\u578b\u6570\u636e\u7684\u5185\u5b58\u5730\u5740\uff0c\u5806\u5185\u5b58\u50a8\u5b58\u5f15\u7528\u7c7b\u578b\u7684\u6570\u636e<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/17149730709e41a4.jpg\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2737\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/17149730709e41a4.jpg\" alt=\"17149730709e41a4\" width=\"988\" height=\"388\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<blockquote><p>\u6808\u5185\u5b58\u7684\u56de\u6536\uff1a<\/p><\/blockquote>\n<p>\u6808\u5185\u5b58\u8c03\u7528\u6808\u4e0a\u4e0b\u6587\u5207\u6362\u540e\u5c31\u88ab\u56de\u6536\uff0c\u6bd4\u8f83\u7b80\u5355<\/p>\n<blockquote><p>\u5806\u5185\u5b58\u7684\u56de\u6536\uff1a<\/p><\/blockquote>\n<p>V8\u7684\u5806\u5185\u5b58\u5206\u4e3a\u65b0\u751f\u4ee3\u5185\u5b58\u548c\u8001\u751f\u4ee3\u5185\u5b58\uff0c\u65b0\u751f\u4ee3\u5185\u5b58\u662f\u4e34\u65f6\u5206\u914d\u7684\u5185\u5b58\uff0c\u5b58\u5728\u65f6\u95f4\u77ed\uff0c\u8001\u751f\u4ee3\u5185\u5b58\u5b58\u5728\u65f6\u95f4\u957f<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>\u65b0\u751f\u4ee3\u5185\u5b58\u56de\u6536\u673a\u5236\uff1a\n<ul>\n<li>\u65b0\u751f\u4ee3\u5185\u5b58\u5bb9\u91cf\u5c0f\uff0c64\u4f4d\u7cfb\u7edf\u4e0b\u4ec5\u670932M\u3002\u65b0\u751f\u4ee3\u5185\u5b58\u5206\u4e3a<strong>From\u3001To<\/strong>\u4e24\u90e8\u5206\uff0c\u8fdb\u884c\u5783\u573e\u56de\u6536\u65f6\uff0c\u5148\u626b\u63cfFrom\uff0c\u5c06\u975e\u5b58\u6d3b\u5bf9\u8c61\u56de\u6536\uff0c\u5c06\u5b58\u6d3b\u5bf9\u8c61\u987a\u5e8f\u590d\u5236\u5230To\u4e2d\uff0c\u4e4b\u540e\u8c03\u6362From\/To\uff0c\u7b49\u5f85\u4e0b\u4e00\u6b21\u56de\u6536<\/li>\n<\/ul>\n<\/li>\n<li>\u8001\u751f\u4ee3\u5185\u5b58\u56de\u6536\u673a\u5236\n<ul>\n<li><strong>\u664b\u5347<\/strong>\uff1a\u5982\u679c\u65b0\u751f\u4ee3\u7684\u53d8\u91cf\u7ecf\u8fc7\u591a\u6b21\u56de\u6536\u4f9d\u7136\u5b58\u5728\uff0c\u90a3\u4e48\u5c31\u4f1a\u88ab\u653e\u5165\u8001\u751f\u4ee3\u5185\u5b58\u4e2d<\/li>\n<li><strong>\u6807\u8bb0\u6e05\u9664<\/strong>\uff1a\u8001\u751f\u4ee3\u5185\u5b58\u4f1a\u5148\u904d\u5386\u6240\u6709\u5bf9\u8c61\u5e76\u6253\u4e0a\u6807\u8bb0\uff0c\u7136\u540e\u5bf9\u6b63\u5728\u4f7f\u7528\u6216\u88ab\u5f3a\u5f15\u7528\u7684\u5bf9\u8c61\u53d6\u6d88\u6807\u8bb0\uff0c\u56de\u6536\u88ab\u6807\u8bb0\u7684\u5bf9\u8c61<\/li>\n<li><strong>\u6574\u7406\u5185\u5b58\u788e\u7247<\/strong>\uff1a\u628a\u5bf9\u8c61\u632a\u5230\u5185\u5b58\u7684\u4e00\u7aef<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<blockquote><p>\u53c2\u8003\u8d44\u6599\uff1a<a href=\"https:\/\/juejin.im\/post\/5ad3f1156fb9a028b86e78be#heading-10\">\u804a\u804aV8\u5f15\u64ce\u7684\u5783\u573e\u56de\u6536<\/a><\/p><\/blockquote>\n<h2>4. JS\u76f8\u8f83\u4e8eC++\u7b49\u8bed\u8a00\u4e3a\u4ec0\u4e48\u6162\uff0cV8\u505a\u4e86\u54ea\u4e9b\u4f18\u5316<\/h2>\n<ol>\n<li>JS\u7684\u95ee\u9898\uff1a\n<ul>\n<li><strong>\u52a8\u6001\u7c7b\u578b<\/strong>\uff1a\u5bfc\u81f4\u6bcf\u6b21\u5b58\u53d6\u5c5e\u6027\/\u5bfb\u6c42\u65b9\u6cd5\u65f6\u5019\uff0c\u90fd\u9700\u8981\u5148\u68c0\u67e5\u7c7b\u578b\uff1b\u6b64\u5916\u52a8\u6001\u7c7b\u578b\u4e5f\u5f88\u96be\u5728\u7f16\u8bd1\u9636\u6bb5\u8fdb\u884c\u4f18\u5316<\/li>\n<li><strong>\u5c5e\u6027\u5b58\u53d6<\/strong>\uff1aC++\/Java\u7b49\u8bed\u8a00\u4e2d\u65b9\u6cd5\u3001\u5c5e\u6027\u662f\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u7684\uff0c\u4ec5\u9700\u6570\u7ec4\u4f4d\u79fb\u5c31\u53ef\u4ee5\u83b7\u53d6\uff0c\u800cJS\u5b58\u50a8\u5728\u5bf9\u8c61\u4e2d\uff0c\u6bcf\u6b21\u83b7\u53d6\u90fd\u8981\u8fdb\u884c\u54c8\u5e0c\u67e5\u8be2<\/li>\n<\/ul>\n<\/li>\n<li>V8\u7684\u4f18\u5316\uff1a\n<ul>\n<li><strong>\u4f18\u5316JIT(\u5373\u65f6\u7f16\u8bd1)<\/strong>\uff1a\u76f8\u8f83\u4e8eC++\/Java\u8fd9\u7c7b\u7f16\u8bd1\u578b\u8bed\u8a00\uff0cJS\u4e00\u8fb9\u89e3\u91ca\u4e00\u8fb9\u6267\u884c\uff0c\u6548\u7387\u4f4e\u3002V8\u5bf9\u8fd9\u4e2a\u8fc7\u7a0b\u8fdb\u884c\u4e86\u4f18\u5316\uff1a\u5982\u679c\u4e00\u6bb5\u4ee3\u7801\u88ab\u6267\u884c\u591a\u6b21\uff0c\u90a3\u4e48V8\u4f1a\u628a\u8fd9\u6bb5\u4ee3\u7801\u8f6c\u5316\u4e3a\u673a\u5668\u7801\u7f13\u5b58\u4e0b\u6765\uff0c\u4e0b\u6b21\u8fd0\u884c\u65f6\u76f4\u63a5\u4f7f\u7528\u673a\u5668\u7801\u3002<\/li>\n<li><strong>\u9690\u85cf\u7c7b<\/strong>\uff1a\u5bf9\u4e8eC++\u8fd9\u7c7b\u8bed\u8a00\u6765\u8bf4\uff0c\u4ec5\u9700\u51e0\u4e2a\u6307\u4ee4\u5c31\u80fd\u901a\u8fc7\u504f\u79fb\u91cf\u83b7\u53d6\u53d8\u91cf\u4fe1\u606f\uff0c\u800cJS\u9700\u8981\u8fdb\u884c\u5b57\u7b26\u4e32\u5339\u914d\uff0c\u6548\u7387\u4f4e\uff0cV8\u501f\u7528\u4e86\u7c7b\u548c\u504f\u79fb\u4f4d\u7f6e\u7684\u601d\u60f3\uff0c\u5c06\u5bf9\u8c61\u5212\u5206\u6210\u4e0d\u540c\u7684\u7ec4\uff0c\u5373\u9690\u85cf\u7c7b<\/li>\n<li><strong>\u5185\u5d4c\u7f13\u5b58<\/strong>\uff1a\u5373\u7f13\u5b58\u5bf9\u8c61\u67e5\u8be2\u7684\u7ed3\u679c\u3002\u5e38\u89c4\u67e5\u8be2\u8fc7\u7a0b\u662f\uff1a\u83b7\u53d6\u9690\u85cf\u7c7b\u5730\u5740 -&gt; \u6839\u636e\u5c5e\u6027\u540d\u67e5\u627e\u504f\u79fb\u503c -&gt; \u8ba1\u7b97\u8be5\u5c5e\u6027\u5730\u5740\uff0c\u5185\u5d4c\u7f13\u5b58\u5c31\u662f\u5bf9\u8fd9\u4e00\u8fc7\u7a0b\u7ed3\u679c\u7684\u7f13\u5b58<\/li>\n<li><strong>\u5783\u573e\u56de\u6536\u7ba1\u7406<\/strong>\uff1a\u4e0a\u6587\u5df2\u4ecb\u7ecd<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/1714a1f7c054c657.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2739\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2020\/04\/1714a1f7c054c657.png\" alt=\"1714a1f7c054c657\" width=\"2124\" height=\"1368\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<blockquote><p>\u53c2\u8003\u8d44\u6599\uff1a<a href=\"https:\/\/zhuanlan.zhihu.com\/p\/27628685\">\u4e3a\u4ec0\u4e48V8\u5f15\u64ce\u8fd9\u4e48\u5feb\uff1f<\/a><\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h1><\/h1>\n<ol>\n<li>\u94fe\u63a5\uff1a<a class=\"url\" href=\"https:\/\/juejin.im\/post\/5e8b261ae51d4546c0382ab4\" target=\"_blank\">https:\/\/juejin.im\/post\/5e8b261ae51d4546c0382ab4<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c06\u4ece\u4ee5\u4e0b\u5341\u4e00\u4e2a\u7ef4\u5ea6\u4e3a\u8bfb\u8005\u603b\u7ed3\u524d\u7aef\u57fa\u7840\u77e5\u8bc6 &nbsp; JS\u57fa\u7840 1. \u5982\u4f55\u5728ES5\u73af\u5883\u4e0b\u5b9e\u73b0let \u5bf9\u4e8e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[109,105],"tags":[],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2727"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2727"}],"version-history":[{"count":6,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2727\/revisions"}],"predecessor-version":[{"id":2746,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2727\/revisions\/2746"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}