{"id":93,"date":"2020-12-27T21:38:07","date_gmt":"2020-12-27T13:38:07","guid":{"rendered":"http:\/\/qqiuklele.cn\/?p=93"},"modified":"2025-03-26T15:20:45","modified_gmt":"2025-03-26T07:20:45","slug":"javascript%e7%9a%84%e5%8e%9f%e5%9e%8b%e9%93%be%e4%b8%8e%e5%9f%ba%e4%ba%8e%e5%8e%9f%e5%9e%8b%e9%93%be%e7%9a%84%e7%bb%a7%e6%89%bf","status":"publish","type":"post","link":"https:\/\/qqiukulele.cn\/?p=93","title":{"rendered":"JavaScript\u7684\u539f\u578b\u94fe\u4e0e\u57fa\u4e8e\u539f\u578b\u94fe\u7684\u7ee7\u627f"},"content":{"rendered":"\n<p>\u6df1\u5165\u5b66\u4e60JavaScript\u7684\u4eba\u90fd\u77e5\u9053\uff0cJavaScript\u4e5f\u662f\u95e8\u652f\u6301\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u8bed\u8a00\u3002\u9762\u5411\u5bf9\u8c61\u7684\u8bed\u8a00\u6709\u4e00\u4e2a\u6807\u5fd7\uff0c\u5c31\u662f\u5b83\u4eec\u90fd\u6709\u7c7b\u7684\u6982\u5ff5\uff0c\u901a\u8fc7\u7c7b\u53ef\u4ee5\u521b\u5efa\u4efb\u610f\u591a\u4e2a\u5177\u6709\u76f8\u540c\u5c5e\u6027\u548c\u65b9\u5f0f\u7684\u5bf9\u8c61\u3002\u7136\u9e45\uff0cECMAScript\u91cc\u6ca1\u6709\u7c7b\u7684\u6982\u5ff5\uff0c\uff08ES6\u7684class\u4e5f\u53ea\u662f\u4e00\u79cd\u8bed\u6cd5\u7cd6\uff0c\u5b83\u4ecd\u7136\u662f\u57fa\u4e8e\u539f\u578b\u7684\uff09\uff0c\u4f46\u662fJavaScript\u53ef\u4ee5\u901a\u8fc7<strong>\u539f\u578b\u94fe<\/strong>\u673a\u5236\u4e3a\u5bf9\u8c61\u63d0\u4f9b\u201c\u7ee7\u627f\u201d\u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u5728\u4e86\u89e3\u539f\u578b\u94fe\u4e4b\u524d\uff0c\u6211\u89c9\u5f97\u4e86\u89e3\u4e00\u4e0b<a href=\"http:\/\/www.ruanyifeng.com\/blog\/2011\/06\/designing_ideas_of_inheritance_mechanism_in_javascript.html\">JavaScript\u7684\u7ee7\u627f\u8bbe\u8ba1\u601d\u60f3<\/a>\uff0c\u4e5f\u5c31\u662f\u8bbe\u8ba1JavaScript\u7684\u5927\u795e\u7684\u8bbe\u8ba1\u60f3\u6cd5\u548c\u6545\u4e8b\uff0c\u662f\u633a\u6709\u5e2e\u52a9\u7684\u3002<\/p>\n\n\n\n<p>\u5728\u6211\u4e00\u5f00\u59cb\u5b66\u4e60\u539f\u578b\u548c\u539f\u578b\u94fe\u7684\u65f6\u5019\uff0c\u6211\u662f\u633a\u6df7\u4e71\u7684\uff0c\u50cfprototype\u3001_proto__\u3001constructor\u7b49\u7b49\uff0c\u4ee5\u53ca\u5b83\u4eec\u7684\u5404\u79cd\u6307\u5411\uff0c\u90fd\u628a\u6211\u5f04\u6655\u4e86\uff08\u4e8c\u4ed9\u6865\u5927\u53d4\u8fd9\u6837\u8bf4?\uff09\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u7406\u89e3\u539f\u578b\u5bf9\u8c61<\/strong><\/h2>\n\n\n\n<p>\u5728JavaScript\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u51fd\u6570\uff0c\u5c31\u4f1a\u81ea\u52a8\u4e3a\u8fd9\u4e2a\u51fd\u6570\u521b\u5efa\u4e00\u4e2a<strong>prototype\u5c5e\u6027<\/strong>\uff0c\u8fd9\u4e2a\u5c5e\u6027<strong>\u6307\u5411\u51fd\u6570\u7684\u539f\u578b\u5bf9\u8c61<\/strong>\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u539f\u578b\u5bf9\u8c61\u90fd\u4f1a\u81ea\u52a8\u83b7\u5f97\u4e00\u4e2a<strong>constructor\uff08\u6784\u9020\u51fd\u6570\uff09<\/strong>\u5c5e\u6027\uff0c\u8fd9\u4e2a\u5c5e\u6027\u662f\u4e00\u4e2a\u6307\u5411prototype\u5c5e\u6027\u6240\u5728\u51fd\u6570\u7684\u6307\u9488\u3002\u5f53\u8c03\u7528\u6784\u9020\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u65b0\u5b9e\u4f8b\u540e\uff0c\u8be5\u5b9e\u4f8b\u7684\u5185\u90e8\u4e5f\u5c06\u5305\u542b\u4e00\u4e2a\u6307\u9488\uff08\u79c1\u6709\u5c5e\u6027\uff09\uff0c\u6307\u5411\u6784\u9020\u51fd\u6570\u7684\u539f\u578b\u5bf9\u8c61\uff0c\u79f0\u4e4b\u4e3a <strong>_proto__<\/strong>\u3002<\/p>\n\n\n\n<p>\u53ef\u4ee5\u634b\u4e00\u634b\u7684\u3002\u6211\u4ee5\u6211\u7684\u7406\u89e3\u6362\u79cd\u8bdd\u8bf4\u3002JavaScript\u4e2d\u6240\u6709\u7684\u51fd\u6570\uff08<em>\u9664\u7bad\u5934\u51fd\u6570\u5916<\/em>\uff09\u90fd\u6709\u4e00\u4e2a<span style=\"color: red\">prototype\u5c5e\u6027<\/span>\uff0c\u4e14\u53ea\u6709\u51fd\u6570\u624d\u6709\u3002\u539f\u578b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u90fd\u80fd\u88ab\u6784\u9020\u51fd\u6570\u7684\u5b9e\u4f8b\u5bf9\u8c61\u6240\u5171\u4eab\u3002\u5bf9\u8c61\u539f\u578b\u7684\u771f\u5b9e\u503c\u88ab\u5b58\u50a8\u5728\u5185\u90e8\u4e13\u7528\u5c5e\u6027[[Prototype]]\u4e2d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">       function Person(){}\n &nbsp; &nbsp; &nbsp; Person.prototype.sayHello=()=&gt;{console.log('hello');}\n &nbsp; &nbsp; &nbsp; let QQi = new Person();\n &nbsp; &nbsp; &nbsp; let mom = new Person();\n &nbsp; &nbsp; &nbsp; QQi.sayHello()\/\/hello\n &nbsp; &nbsp; &nbsp; mom.sayHello()\/\/hello  \u5171\u4eab\u8bbf\u95ee\n &nbsp; &nbsp; &nbsp; delete Person.prototype.sayHello; &nbsp;\/\/\u5220\u9664\u65b9\u6cd5\n &nbsp; &nbsp; &nbsp; QQi.sayHello();\/\/\u62a5\u9519<\/pre>\n\n\n\n<p>JavaScript\u4e2d<span style=\"color:red\">constructor<\/span>\u5b58\u5728\u4e8e\u6bcf\u4e00\u4e2a\u51fd\u6570\u7684prototype\u5c5e\u6027\u4e2d\uff0c\u5176\u4e2d\u4fdd\u5b58\u4e86\u6307\u5411\u8be5\u51fd\u6570\u7684\u4e00\u4e2a\u5f15\u7528\uff0c\u4e5f\u5c31\u662fconstructor\u6307\u5411\u4e86\u51fd\u6570\u672c\u8eab\u3002\u5f53\u4f7f\u7528new\u5173\u952e\u5b57\u8c03\u7528\u51fd\u6570\u65f6\uff0c\u6267\u884c\u7684\u662f\u5185\u90e8\u65b9\u6cd5[[Construtor]]\u51fd\u6570\uff0c\u5b83\u4f1a\u521b\u5efa\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u7136\u540e\u518d\u6267\u884c\u51fd\u6570\u4f53\uff0c\u5c06this\u7ed1\u5b9a\u5230\u5b9e\u4f8b\u4e0a\u3002\u8981\u6ce8\u610f\u7684\u662f\uff0c\u7bad\u5934\u51fd\u6570\u6ca1\u6709this\uff0c\u800c\u662f\u901a\u8fc7\u67e5\u627e\u4f5c\u7528\u57df\u94fe\u51b3\u5b9athis\u503c\u5f97\uff0c\u6240\u4ee5\u4ed6\u4e0d\u5177\u6709[[Constructor]]\u65b9\u6cd5\uff0c\u4e0d\u80fd\u88abnew\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(Person.prototype.constructor);\/\/ \u0192 Person(){}<br>console.log(Person.prototype.constructor === Person)\/\/true<\/pre>\n\n\n\n<p>JavaScript\u4e2d\u5b9e\u4f8b\u5bf9\u8c61\u90fd\u6709\u4e00\u4e2a\u5185\u7f6e\u5c5e\u6027\uff0c\u5373<span style=\"color: red\">_proto__(\u9690\u5f0f\u539f\u578b\u94fe\u5c5e\u6027)<\/span>\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u5b83\u6307\u5411\u521b\u5efa\u5b83\u7684\u6784\u9020\u51fd\u6570\u7684prototype\u5c5e\u6027\u3002\u51fd\u6570\u4f5c\u4e3a\u5bf9\u8c61\uff0c\u4e5f\u6709\u8fd9\u4e2a\u5c5e\u6027\u3002\u8bf7\u8bb0\u4f4f\uff0c<strong>\u5b9e\u4f8b\u7684\u6307\u9488\u4ec5\u4ec5\u6307\u5411\u539f\u578b\uff0c\u800c\u4e0d\u6307\u5411\u6784\u9020\u51fd\u6570\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> console.log( QQi.__proto__)<br> console.log( Person.prototype)<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/qqiukulele.cn\/wp-content\/uploads\/2020\/12\/JHTKSBWG5ZSGCDWAE0N.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/qqiukulele.cn\/wp-content\/uploads\/2020\/12\/JHTKSBWG5ZSGCDWAE0N.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><figcaption class=\"wp-element-caption\">\u4e24\u4e2a\u7684\u6253\u5370\u662f\u4e00\u6837\u7684<\/figcaption><\/figure>\n\n\n\n<p>\u5728ES6\u4e2d\uff0c\u5f15\u5165\u4e86Super\uff0c\u53ef\u4ee5\u7b80\u5316\u539f\u578b\u8bbf\u95ee\uff0c\u7279\u522b\u5728\u591a\u91cd\u7ee7\u627f\u4e0b\u4f7f\u7528\u8d77\u6765\u4f1a\u611f\u89c9\u5f88\u5999\u3002\u56e0\u4e3aSuper\u80fd\u4fdd\u8bc1\u6307\u5411\u6b63\u786e\u7684\u5bf9\u8c61\u3002\uff08\u4f7f\u7528\u8d77\u6765\u5c31\u611f\u89c9\u548cJava\u4e2d\u7684super\u5173\u952e\u5b57\u7528\u8d77\u6765\u7684\u611f\u89c9\u5dee\u4e0d\u591a\uff1f\uff09<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7406\u89e3\u539f\u578b\u94fe<\/h2>\n\n\n\n<p>\u4e0d\u8fc7\u6211\u4eec\u5728\u8fdb\u884c\u9875\u9762\u5f00\u53d1\u6216\u8005\u5199\u4ee3\u7801\u65f6\uff0c\u5f88\u5c11\u4f1a\u4e3b\u52a8\u5199\u5230prototype\uff0c\u5b83\u7684\u4e3b\u8981\u4f5c\u7528\u5c31\u662f\u5f53js\u5f15\u64ce\u67e5\u627e\u5bf9\u8c61\u7684\u67d0\u4e2a\u5c5e\u6027\u65f6\uff0c\u5148\u67e5\u627e\u5bf9\u8c61\u672c\u8eab\u662f\u5426\u5b58\u5728\u8be5\u5c5e\u6027\uff0c\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5c31\u4f1a\u5728\u539f\u578b\u94fe\u4e0a\u4e00\u5c42\u4e00\u5c42\u7f51\u4e0a\u67e5\u627e\u3002\u6240\u4ee5\u7406\u89e3\u539f\u578b\u548c\u539f\u578b\u94fe\uff0c\u6709\u52a9\u4e8e\u6211\u4eec\u66f4\u597d\u7684\u7406\u89e3\u8fd9\u95e8\u8bed\u8a00\uff0c\u7528\u597d\u8fd9\u95e8\u8bed\u8a00\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u600e\u4e48\u4e13\u4e1a\u5730\u56de\u7b54\uff1a\u201c\u539f\u578b\u94fe\u662f\u4ec0\u4e48\uff1f\u600e\u4e48\u5b9e\u73b0\u7684\uff1f\u201d\u2014\u2014<strong>\u6211\u4eec\u8ba9\u539f\u578b\u5bf9\u8c61\u7b49\u4e8e\u53e6\u4e00\u4e2a\u7c7b\u578b\u7684\u5b9e\u4f8b\uff0c\u539f\u578b\u5bf9\u8c61\u5c06\u5305\u542b\u4e00\u4e2a\u6307\u5411\u53e6\u4e00\u4e2a\u539f\u578b\u7684\u6307\u9488\uff0c\u4e0d\u65ad\u5957\u5a03\uff0c\u5c42\u5c42\u9012\u8fdb\uff0c\u5c31\u6784\u6210\u4e86\u5b9e\u4f8b\u4e0e\u539f\u578b\u7684\u94fe\u6761\u3002\u8fd9\u5c31\u662f\u6240\u8c13\u7684\u539f\u578b\u94fe\u3002<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u539f\u578b\u94fe\u7684\u6784\u5efa\u662f\u901a\u8fc7\u5c06\u4e00\u4e2a\u7c7b\u578b\u7684\u5b9e\u4f8b\u8d4b\u503c\u7ed9\u53e6\u4e00\u4e2a\u6784\u9020\u51fd\u6570\u7684\u539f\u578b\u5b9e\u73b0\u7684\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u4e0b\u9762\u6709\u4e2a\u6709\u5173\u539f\u578b\u94fe\u7684\u5c0f\u4f8b\u5b50\uff0c\u5c31\u662fPerson\u6ca1\u6709\u5b9a\u4e49\u6216\u8005\u91cd\u5199toString\u65b9\u6cd5\uff0c\u4ecd\u7136\u53ef\u4ee5\u8c03\u7528toString()\u65b9\u6cd5\uff0c\u8fd9\u4e2a\u5c31\u662f\u901a\u8fc7\u539f\u578b\u94fe\uff0cPerson\u7684\u539f\u578b\u662fObject\uff0cObject\u6709toString\u65b9\u6cd5\uff0c\u90a3\u5c31\u627e\u5230\u4e86toString\u65b9\u6cd5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(QQi.toString());\/\/[object Object]<br>console.log(QQi.__proto__.__proto__.toString === QQi.toString);\/\/true<\/pre>\n\n\n\n<p>\u539f\u578b\u94fe\u7684\u7ec8\u70b9\u662f\u4ec0\u4e48\uff0c\u6bd5\u7adf\u4e00\u6761\u94fe\u5b50\u4e0d\u53ef\u80fd\u65e0\u9650\u957f\u3002\u6211\u4eec\u77e5\u9053\uff0cJavaScript\u91cc\uff0c\u6240\u6709\u5f15\u7528\u7c7b\u578b\u9ed8\u8ba4\u90fd\u7ee7\u627fObject\uff0c\u90a3\u4e48Object\u7ee7\u627f\u4ec0\u4e48\uff1f\u8fd8\u662fObject\u5c31\u662f\u7ec8\u70b9\uff1f<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> &nbsp;console.log(Object.prototype.__proto__); \/\/null<\/pre>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230Object\u7684\u539f\u578b\u7684\u6307\u9488\u6307\u5411\u4e86null\uff0c\u90a3\u4e48null\u4e0d\u53ef\u80fd\u518d\u6709\u6307\u5411\u4e86\uff0c\u90a3\u4e48<strong>null\u5c31\u662f\u539f\u578b\u94fe\u7684\u7ec8\u70b9\u4e86\u3002<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7ee7\u627f\u6a21\u5f0f<\/h2>\n\n\n\n<p>JavaScript\u7684\u7ee7\u627f\u4e3b\u8981\u57fa\u4e8e\u539f\u578b\u94fe\u3002\u5728JavaScript\u91cc\u6709\u5f88\u591a\u7684\u7ee7\u627f\u6a21\u5f0f\uff0c\u6211\u4e5f\u662f\u5b66\u4e60\u548c\u53c2\u8003\u7684\u300aJavaScript\u9ad8\u7ea7\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u300b\u8fd9\u672c\u4e66\uff0c\u6211\u5c06\u634b\u4e00\u634b\u7ec4\u5408\u7ee7\u627f\uff0c\u4e00\u79cd\u6700\u5e38\u7528\u7684\u7ee7\u627f\u6a21\u5f0f\uff1b\u5bc4\u751f\u7ec4\u5408\u5f0f\u7ee7\u627f\uff0c\u4e00\u4e2a\u5f15\u7528\u7c7b\u578b\u6700\u7406\u60f3\u7684\u8303\u5f0f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7ec4\u5408\u7ee7\u627f<\/h3>\n\n\n\n<p>\u7ec4\u5408\u6307\u7684\u662f\u4f7f\u7528\u6784\u9020\u51fd\u6570\u548c\u539f\u578b\u6a21\u5f0f\u6765\u5b9e\u73b0\u7ee7\u627f\u3002\u6784\u9020\u51fd\u6570\u5b9a\u4e49\u5b9e\u4f8b\u5c5e\u6027\uff0c\u539f\u578b\u6a21\u5f0f\u7528\u4e8e\u81ea\u5b9a\u4e49\u65b9\u6cd5\u548c\u5171\u4eab\u7684\u5c5e\u6027\u3002\u8fd9\u79cd\u7ec4\u5408\u6a21\u5f0f\u53ef\u4ee5\u8ba9\u6bcf\u4e2a\u5b9e\u4f8b\u6709\u81ea\u5df1\u7684\u4e00\u4e9b\u7279\u6b8a\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u5b9e\u4f8b\u95f4\u4e0d\u4f1a\u4e92\u76f8\u5f71\u54cd\uff0c\u800c\u901a\u8fc7\u539f\u578b\u53ef\u4ee5\u8ba9\u4e00\u4e9b\u5c5e\u6027\u548c\u65b9\u6cd5\u4f9b\u6bcf\u4e2a\u5b9e\u4f8b\u5171\u4eab\uff0c\u5b9e\u73b0\u590d\u7528\uff0c\u8282\u7701\u5185\u5b58\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> function Person(name) {<br> &nbsp; &nbsp; &nbsp; &nbsp;this.name = name;<br> &nbsp;  }<br> &nbsp; &nbsp;Person.prototype.sayName = function(){<br> &nbsp; &nbsp; &nbsp; &nbsp;constructor: Person,\/\/\u521b\u5efa\u65b0\u7684\u51fd\u6570\u65f6\u53ef\u80fd\u4f1a\u628a\u6784\u9020\u51fd\u6570\u91cd\u5199\u6389<br> &nbsp; &nbsp; &nbsp; &nbsp;console.log(this.name);<br> &nbsp;  }<br> &nbsp; &nbsp;function Teacher(name,age) {<br> &nbsp; &nbsp; &nbsp; &nbsp;Person.call(this,name) \/\/\u4f20\u53c2<br> &nbsp; &nbsp; &nbsp; &nbsp;this.age = age;<br> &nbsp;  };<br> &nbsp; &nbsp;Teacher.prototype = new Person();\/\/Person\u5b9e\u4f8b\u8d4b\u7ed9Teacher\u539f\u578b<br> &nbsp; &nbsp;Teacher.prototype.constructor = Person;\/\/\u56e0\u4e3a\u5b83\u91cd\u5199\u540econstructoor\u5c31\u662fTeacher\u4e86<br> &nbsp; &nbsp;Teacher.prototype.sayAge = function() {<br> &nbsp; &nbsp; &nbsp; &nbsp;console.log(this.age);<br> &nbsp;  }<br>\u200b<br> &nbsp; &nbsp;let cluo = new Teacher(\"cluo\",28);<br> &nbsp; &nbsp;cluo.sayAge();\/\/28<br> &nbsp; &nbsp;let zhaomeili = new Teacher(\"zhaomeili\",30);<br> &nbsp; &nbsp;zhaomeili.sayName();\/\/zhaomeili<\/pre>\n\n\n\n<p>\u50cf\u8fd9\u6837\uff0ccluo\u548czhaomeili\u90fd\u6709\u81ea\u5df1\u7684\u5c5e\u6027\uff0c\u4f46\u662f\u90fd\u53ef\u4ee5\u8c03\u7528Teacher\u4e0a\u5b9a\u4e49\u7684\u65b0\u65b9\u6cd5\uff0c\u4e5f\u53ef\u4ee5\u8c03\u7528\u4ecePerson\u4e0a\u7ee7\u627f\u6765\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5bc4\u751f\u7ec4\u5408\u5f0f\u7ee7\u627f<\/h3>\n\n\n\n<p>\u76f4\u63a5\u770b\u4ee3\u7801\uff0c\u6bd4\u4e00\u4e0b\u4e0a\u9762\u7684\u7ec4\u5408\u7ee7\u627f\uff0c\u53d8\u5316\u7684\u5730\u65b9\u4e0d\u591a\uff0c\u5c31\u662f\u5bc4\u751f\u7ec4\u5408\u5f0f\u7ee7\u627f\u5199\u4e86\u4e00\u4e2a\u51fd\u6570\uff0c\u5728\u51fd\u6570\u91cc\u8c03\u7528\u4e86\u8d85\u7c7b\u6784\u9020\u51fd\u6570\uff0c\u611f\u89c9\u601d\u8def\u8fd8\u662f\u548c\u4e0a\u9762\u7684\u5dee\u4e0d\u591a\u7684\u3002\u4e0d\u8fc7\u503c\u5f97\u6ce8\u610f\u7684\u5f0f\uff0c\u6574\u4e2a\u201c\u7ee7\u627f\u201d\u8fc7\u7a0b\uff0c\u53ea\u8c03\u7528\u4e86\u4e00\u6b21\u201c\u7236\u7c7b\u201d\u6784\u9020\u51fd\u6570\u3002\u50cf\u4e0a\u9762\u7684\u7ec4\u5408\u7ee7\u627f\uff0c\u201c\u513f\u5b50\u201d\u8c03\u7528\u6784\u9020\u51fd\u6570\u8fd8\u662f\u4f1a\u8c03\u7528\u5230\u201c\u7236\u4eb2\u201d\u6784\u9020\u51fd\u6570\u7684\uff1a Person.call(this,name)\u3002\u6240\u4ee5\u5bc4\u751f\u7ec4\u5408\u5f0f\u7ee7\u627f\u7684\u6548\u7387\u4f1a\u9ad8\u4e00\u70b9\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> <br> &nbsp; &nbsp;function Person(name) {<br> &nbsp; &nbsp; &nbsp; &nbsp;this.name = name;<br> &nbsp;  }<br> &nbsp; &nbsp;Person.prototype.sayName = function(){<br> &nbsp; &nbsp; &nbsp; &nbsp;constructor: Person,\/\/\u521b\u5efa\u65b0\u7684\u51fd\u6570\u65f6\u53ef\u80fd\u4f1a\u628a\u6784\u9020\u51fd\u6570\u91cd\u5199\u6389<br> &nbsp; &nbsp; &nbsp; &nbsp;console.log(this.name);<br> &nbsp;  }<br> &nbsp; &nbsp;function Teacher(name,age) {<br> &nbsp; &nbsp; &nbsp; &nbsp;Person.call(this,name) \/\/\u4f20\u53c2<br> &nbsp; &nbsp; &nbsp; &nbsp;this.age = age;<br> &nbsp;  };<br> &nbsp; <br> &nbsp; &nbsp;function inheritPrototype(Teacher,Person){<br> &nbsp; &nbsp; &nbsp; &nbsp;let prototype = Object(Person.prototype) &nbsp;\/\/\u521b\u5efa\u7236\u539f\u578b\u7684\u4e00\u4e2a\u526f\u672c\u5bf9\u8c61<br> &nbsp; &nbsp; &nbsp; &nbsp;prototype.constructor = Teacher; &nbsp;\/\/\u589e\u5f3a\u5bf9\u8c61 &nbsp; \u4e3a\u526f\u672c\u6dfb\u52a0constructor\u5c5e\u6027<br> &nbsp; &nbsp; &nbsp; &nbsp;Teacher.prototype = prototype; &nbsp;\/\/\u6307\u5b9a\u5bf9\u8c61  \u5c06\u7236\u672c\u8d4b\u503c\u7ed9\u5b50\u7c7b\u578b<br> &nbsp;  }<br>\u200b<br> &nbsp; &nbsp;Teacher.prototype.sayAge = function() {<br> &nbsp; &nbsp; &nbsp; &nbsp;console.log(this.age);<br> &nbsp;  }<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u603b\u7ed3<\/h2>\n\n\n\n<p>\u6bcf\u6b21\u8bf4\u5230\u539f\u578b\u94fe\uff0c\u6211\u8111\u6d77\u91cc\u5c31\u662f\u4e00\u5e45\u753b\u9762\uff1a\u4e00\u76f4\u5c0f\u8717\u725b\uff0c\u6cbf\u7740\u5927\u6811\u7684\u6570\u5e72\uff0c\u4e00\u6b65\u4e00\u6b65\u52aa\u529b\u5f80\u4e0a\u722c\u54c8\u54c8\u54c8\u3002<\/p>\n\n\n\n<p>\u5176\u5b9e\u521a\u5f00\u59cb\u770b\u539f\u578b\u94fe\uff0c\u6211\u5c31\u662f\u88ab\u5404\u79cd\u5355\u8bcd\u540d\u8bcd\u7ed9\u5f04\u6df7\u4e71\u4e86\u3002\u4e00\u5b9a\u8981\u8bb0\u4f4f\uff1a\u6bcf\u4e2a\u6784\u9020\u51fd\u6570\u90fd\u6709\u4e00\u4e2a\u539f\u578b\u5bf9\u8c61\uff0c\u539f\u578b\u5bf9\u8c61\u90fd\u5305\u542b\u4e00\u4e2a\u6307\u5411\u6784\u9020\u51fd\u6570\u7684\u6307\u9488\uff0c\u800c\u5b9e\u4f8b\u90fd\u5305\u542b\u4e00\u4e2a\u6307\u5411\u539f\u578b\u5bf9\u8c61\u7684\u5185\u90e8\u6307\u9488\u3002\u539f\u578b\u94fe\u7684\u6784\u5efa\u662f\u901a\u8fc7\u5c06\u4e00\u4e2a\u7c7b\u578b\u7684\u5b9e\u4f8b\u8d4b\u503c\u7ed9\u53e6\u4e00\u4e2a\u6784\u9020\u51fd\u6570\u7684\u539f\u578b\u5b9e\u73b0\u7684\u3002JavaScript\u7684\u7ee7\u627f\u5c31\u57fa\u4e8e\u539f\u578b\u94fe\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u662f\u65f6\u5019\u8d85\u7ea7\u7528\u5fc3\u4e86\u89e3\u6e05\u695a\u539f\u578b\u94fe\u4e86&#8230;&#8230;\u6ce5\u8fd8\u4e0d\u77e5\u9053\u561b\uff1f?<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[19],"class_list":["post-93","post","type-post","status-publish","format-standard","hentry","category-21","tag-js"],"_links":{"self":[{"href":"https:\/\/qqiukulele.cn\/index.php?rest_route=\/wp\/v2\/posts\/93","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qqiukulele.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qqiukulele.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qqiukulele.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qqiukulele.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=93"}],"version-history":[{"count":4,"href":"https:\/\/qqiukulele.cn\/index.php?rest_route=\/wp\/v2\/posts\/93\/revisions"}],"predecessor-version":[{"id":484,"href":"https:\/\/qqiukulele.cn\/index.php?rest_route=\/wp\/v2\/posts\/93\/revisions\/484"}],"wp:attachment":[{"href":"https:\/\/qqiukulele.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=93"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qqiukulele.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=93"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qqiukulele.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=93"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}