{"id":154316,"date":"2024-05-08T11:30:11","date_gmt":"2024-05-08T03:30:11","guid":{"rendered":""},"modified":"2024-05-08T11:30:14","modified_gmt":"2024-05-08T03:30:14","slug":"%e5%9c%a8-javascript-%e4%b8%ad%ef%bc%8c%e6%9c%89%e5%93%aa%e4%ba%9b%e6%96%b9%e6%b3%95%e5%8f%af%e4%bb%a5%e5%ae%9e%e7%8e%b0%e7%bb%a7%e6%89%bf","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/154316.html","title":{"rendered":"\u5728 JavaScript \u4e2d\uff0c\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u7ee7\u627f"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26212620\/7454f259-ec13-4056-af63-5e358e17074b.webp\" alt=\"\u5728 JavaScript \u4e2d\uff0c\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u7ee7\u627f\" \/><\/p>\n<p><p>\u5728JavaScript\u4e2d\uff0c\u5b9e\u73b0\u7ee7\u627f\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\uff1a<strong>\u539f\u578b\u94fe\u7ee7\u627f<\/strong>\u3001<strong>\u6784\u9020\u51fd\u6570\u7ee7\u627f<\/strong>\u3001<strong>\u7ec4\u5408\u7ee7\u627f<\/strong>\u3001<strong>\u539f\u578b\u5f0f\u7ee7\u627f<\/strong>\u3001<strong>\u5bc4\u751f\u5f0f\u7ee7\u627f<\/strong>\u3001\u548c<strong>\u5bc4\u751f\u7ec4\u5408\u5f0f\u7ee7\u627f<\/strong>\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5404\u5177\u7279\u70b9\uff0c\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u7ee7\u627f\u9700\u6c42\u573a\u666f\u3002<strong>\u5176\u4e2d\uff0c\u539f\u578b\u94fe\u7ee7\u627f\u662f\u6700\u57fa\u672c\u7684\u7ee7\u627f\u65b9\u5f0f<\/strong>\uff0c\u5b83\u901a\u8fc7\u91cd\u5199\u5b50\u7c7b\u7684\u539f\u578b\u5bf9\u8c61\uff0c\u8ba9\u5176\u6307\u5411\u7236\u7c7b\u7684\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u4ece\u800c\u5b9e\u73b0\u7ee7\u627f\u3002\u539f\u578b\u94fe\u7ee7\u627f\u7684\u6838\u5fc3\u5728\u4e8e\u5229\u7528\u539f\u578b\u8ba9\u4e00\u4e2a\u5f15\u7528\u7c7b\u578b\u7ee7\u627f\u53e6\u4e00\u4e2a\u5f15\u7528\u7c7b\u578b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u539f\u578b\u94fe\u7ee7\u627f<\/h3>\n<\/p>\n<p><p>\u5728JavaScript\u4e2d\uff0c\u6bcf\u4e2a\u6784\u9020\u51fd\u6570\u90fd\u6709\u4e00\u4e2a\u539f\u578b\u5bf9\u8c61\uff0c\u539f\u578b\u5bf9\u8c61\u5305\u542b\u4e00\u4e2a\u6307\u5411\u6784\u9020\u51fd\u6570\u7684\u6307\u9488\uff0c\u540c\u65f6\u4e5f\u5305\u542b\u4e86\u4e00\u4e2a\u539f\u578b\u94fe\u3002\u5f53\u5c1d\u8bd5\u8bbf\u95ee\u4e00\u4e2a\u5bf9\u8c61\u7684\u67d0\u4e2a\u5c5e\u6027\u65f6\uff0c\u5982\u679c\u8be5\u5bf9\u8c61\u672c\u8eab\u4e0d\u5b58\u5728\u8fd9\u4e2a\u5c5e\u6027\uff0c\u5219\u4f1a\u67e5\u627e\u5176\u539f\u578b\u5bf9\u8c61\u662f\u5426\u6709\u8fd9\u4e2a\u5c5e\u6027\uff0c\u8fd9\u4e00\u67e5\u627e\u8fc7\u7a0b\u4f1a\u6cbf\u7740\u539f\u578b\u94fe\u5411\u4e0a\u8fdb\u884c\uff0c\u76f4\u81f3\u627e\u5230\u5c5e\u6027\u6216\u8fbe\u5230\u539f\u578b\u94fe\u7684\u9876\u7aef\u3002\u539f\u578b\u94fe\u7ee7\u627f\u6b63\u662f\u57fa\u4e8e\u8fd9\u4e00\u673a\u5236\u3002<\/p>\n<\/p>\n<p><p>\u8981\u5b9e\u73b0\u539f\u578b\u94fe\u7ee7\u627f\uff0c\u53ef\u4ee5\u5c06\u5b50\u7c7b\u7684\u539f\u578b\u8bbe\u7f6e\u4e3a\u7236\u7c7b\u7684\u4e00\u4e2a\u5b9e\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function Parent() {<\/p>\n<p>    this.parentProperty = true;<\/p>\n<p>}<\/p>\n<p>Parent.prototype.getParentProperty = function() {<\/p>\n<p>    return this.parentProperty;<\/p>\n<p>};<\/p>\n<p>function Child() {<\/p>\n<p>    this.childProperty = false;<\/p>\n<p>}<\/p>\n<p>\/\/ \u7ee7\u627f\u81eaParent<\/p>\n<p>Child.prototype = new Parent();<\/p>\n<p>var instance = new Child();<\/p>\n<p>console.log(instance.getParentProperty());  \/\/ true<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u6613\u884c\uff0c\u4f46\u5b58\u5728\u4e24\u5927\u7f3a\u70b9\uff1a\u4e00\u662f\u539f\u578b\u4e2d\u5305\u542b\u7684\u5f15\u7528\u503c\u4f1a\u88ab\u6240\u6709\u5b9e\u4f8b\u5171\u4eab\uff1b\u4e8c\u662f\u5b50\u7c7b\u578b\u5728\u5b9e\u4f8b\u5316\u65f6\u4e0d\u80fd\u7ed9\u7236\u7c7b\u578b\u7684\u6784\u9020\u51fd\u6570\u4f20\u53c2\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u6784\u9020\u51fd\u6570\u7ee7\u627f<\/h3>\n<\/p>\n<p><p>\u6784\u9020\u51fd\u6570\u7ee7\u627f\u662f\u901a\u8fc7\u5728\u5b50\u7c7b\u7684\u6784\u9020\u51fd\u6570\u4e2d\u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u51fd\u6570\u6765\u5b9e\u73b0\u7684\uff0c\u501f\u52a9<code>call()<\/code>\u6216<code>apply()<\/code>\u53ef\u4ee5\u5728\u65b0\u521b\u5efa\u7684\u5bf9\u8c61\u4e0a\u6267\u884c\u6784\u9020\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function Parent(name) {<\/p>\n<p>    this.name = name || &#039;Parent&#039;;<\/p>\n<p>    this.colors = [&#039;red&#039;, &#039;blue&#039;, &#039;green&#039;];<\/p>\n<p>}<\/p>\n<p>function Child(name) {<\/p>\n<p>    \/\/ \u7ee7\u627f\u81eaParent\uff0c\u5e76\u4f20\u53c2<\/p>\n<p>    Parent.call(this, name);<\/p>\n<p>}<\/p>\n<p>var instance1 = new Child(&#039;Child1&#039;);<\/p>\n<p>var instance2 = new Child(&#039;Child2&#039;);<\/p>\n<p>instance1.colors.push(&#039;black&#039;);<\/p>\n<p>console.log(instance1.colors); \/\/ [&#039;red&#039;, &#039;blue&#039;, &#039;green&#039;, &#039;black&#039;]<\/p>\n<p>console.log(instance2.colors); \/\/ [&#039;red&#039;, &#039;blue&#039;, &#039;green&#039;]<\/p>\n<p>console.log(instance1.name); \/\/ Child1<\/p>\n<p>console.log(instance2.name); \/\/ Child2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u7ee7\u627f\u65b9\u5f0f\u89e3\u51b3\u4e86\u539f\u578b\u94fe\u7ee7\u627f\u4e2d\u5f15\u7528\u7c7b\u578b\u5171\u4eab\u7684\u95ee\u9898\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u5b50\u7c7b\u578b\u6784\u9020\u51fd\u6570\u4e2d\u5411\u7236\u7c7b\u578b\u6784\u9020\u51fd\u6570\u4f20\u9012\u53c2\u6570\u3002\u4f46\u662f\uff0c\u8fd9\u79cd\u65b9\u6cd5\u65e0\u6cd5\u7ee7\u627f\u7236\u7c7b\u539f\u578b\u4e0a\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u7ec4\u5408\u7ee7\u627f<\/h3>\n<\/p>\n<p><p>\u7ec4\u5408\u7ee7\u627f\u7ed3\u5408\u4e86\u539f\u578b\u94fe\u7ee7\u627f\u548c\u6784\u9020\u51fd\u6570\u7ee7\u627f\u7684\u4f18\u70b9\uff0c\u5373\u901a\u8fc7\u6784\u9020\u51fd\u6570\u7ee7\u627f\u5c5e\u6027\uff0c\u901a\u8fc7\u539f\u578b\u94fe\u7684\u6df7\u6210\u5f62\u5f0f\u7ee7\u627f\u65b9\u6cd5\u3002\u8fd9\u662fJavaScript\u4e2d\u6700\u5e38\u7528\u7684\u7ee7\u627f\u6a21\u5f0f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function Parent(name) {<\/p>\n<p>    this.name = name;<\/p>\n<p>    this.colors = [&#039;red&#039;, &#039;blue&#039;, &#039;green&#039;];<\/p>\n<p>}<\/p>\n<p>Parent.prototype.getName = function() {<\/p>\n<p>    return this.name;<\/p>\n<p>};<\/p>\n<p>function Child(name, age) {<\/p>\n<p>    \/\/ \u7ee7\u627f\u5c5e\u6027<\/p>\n<p>    Parent.call(this, name);<\/p>\n<p>    \/\/ \u65b0\u5c5e\u6027<\/p>\n<p>    this.age = age;<\/p>\n<p>}<\/p>\n<p>\/\/ \u7ee7\u627f\u65b9\u6cd5<\/p>\n<p>Child.prototype = new Parent();<\/p>\n<p>Child.prototype.constructor = Child;<\/p>\n<p>Child.prototype.getAge = function() {<\/p>\n<p>    return this.age;<\/p>\n<p>};<\/p>\n<p>var instance = new Child(&#039;Nicholas&#039;, 29);<\/p>\n<p>console.log(instance.getName()); \/\/ Nicholas<\/p>\n<p>console.log(instance.getAge()); \/\/ 29<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7ec4\u5408\u7ee7\u627f\u907f\u514d\u4e86\u539f\u578b\u94fe\u548c\u6784\u9020\u51fd\u6570\u7ee7\u627f\u7684\u7f3a\u70b9\uff0c\u540c\u65f6\u83b7\u5f97\u4e86\u4e8c\u8005\u7684\u4f18\u70b9\u3002\u7136\u800c\uff0c\u8fd9\u79cd\u7c7b\u578b\u7684\u7ee7\u627f\u4e5f\u5b58\u5728\u6548\u7387\u95ee\u9898\uff0c\u7236\u7c7b\u6784\u9020\u51fd\u6570\u4f1a\u88ab\u6267\u884c\u4e24\u6b21\uff0c\u4e00\u6b21\u662f\u8bbe\u7f6e\u5b50\u7c7b\u578b\u539f\u578b\u7684\u65f6\u5019\uff0c\u4e00\u6b21\u662f\u5728\u5b50\u7c7b\u578b\u6784\u9020\u51fd\u6570\u5185\u90e8\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u539f\u578b\u5f0f\u7ee7\u627f<\/h3>\n<\/p>\n<p><p>Douglas Crockford\u63d0\u51fa\u4e86\u539f\u578b\u5f0f\u7ee7\u627f\uff0c\u8fd9\u79cd\u7ee7\u627f\u65b9\u5f0f\u4e0d\u5fc5\u9884\u5148\u5b9a\u4e49\u6784\u9020\u51fd\u6570\uff0c\u800c\u662f\u76f4\u63a5\u901a\u8fc7\u514b\u9686\u4e00\u4e2a\u73b0\u6709\u5bf9\u8c61\u6765\u5b9e\u73b0\u7ee7\u627f\u3002ECMAScript 5\u901a\u8fc7\u65b0\u589e<code>Object.create()<\/code>\u65b9\u6cd5\u6807\u51c6\u5316\u4e86\u539f\u578b\u5f0f\u7ee7\u627f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">var person = {<\/p>\n<p>    name: &#039;Nicholas&#039;,<\/p>\n<p>    friends: [&#039;Shelby&#039;, &#039;Court&#039;, &#039;Van&#039;]<\/p>\n<p>};<\/p>\n<p>var anotherPerson = Object.create(person);<\/p>\n<p>anotherPerson.name = &#039;Greg&#039;;<\/p>\n<p>anotherPerson.friends.push(&#039;Rob&#039;);<\/p>\n<p>var yetAnotherPerson = Object.create(person);<\/p>\n<p>yetAnotherPerson.name = &#039;Linda&#039;;<\/p>\n<p>yetAnotherPerson.friends.push(&#039;Barbie&#039;);<\/p>\n<p>console.log(person.friends); \/\/ [&quot;Shelby&quot;, &quot;Court&quot;, &quot;Van&quot;, &quot;Rob&quot;, &quot;Barbie&quot;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u7f3a\u70b9\u548c\u539f\u578b\u94fe\u7ee7\u627f\u4e00\u6837\uff0c\u5305\u542b\u5f15\u7528\u7c7b\u578b\u7684\u5c5e\u6027\u503c\u59cb\u7ec8\u4f1a\u88ab\u6240\u6709\u5b9e\u4f8b\u5171\u4eab\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5bc4\u751f\u5f0f\u7ee7\u627f<\/h3>\n<\/p>\n<p><p>\u5bc4\u751f\u5f0f\u7ee7\u627f\u4e0e\u539f\u578b\u5f0f\u7ee7\u627f\u7d27\u5bc6\u76f8\u5173\uff0c\u5b83\u662f\u4e00\u79cd\u589e\u5f3a\u5bf9\u8c61\u7684\u65b9\u6cd5\uff0c\u5373\u5728\u539f\u578b\u5f0f\u7ee7\u627f\u7684\u57fa\u7840\u4e0a\u518d\u6dfb\u52a0\u65b9\u6cd5\u6216\u5c5e\u6027\u3002\u5b83\u9002\u7528\u4e8e\u4e3b\u8981\u5173\u6ce8\u5bf9\u8c61\u800c\u4e0d\u662f\u81ea\u5b9a\u4e49\u7c7b\u578b\u548c\u6784\u9020\u51fd\u6570\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function createAnother(original){<\/p>\n<p>    var clone = Object.create(original); \/\/ \u901a\u8fc7\u8c03\u7528\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u65b0\u5bf9\u8c61<\/p>\n<p>    clone.sayHi = function() { \/\/ \u4ee5\u67d0\u79cd\u65b9\u5f0f\u6765\u589e\u5f3a\u8fd9\u4e2a\u5bf9\u8c61<\/p>\n<p>        console.log(&#039;hi&#039;);<\/p>\n<p>    };<\/p>\n<p>    return clone;<\/p>\n<p>}<\/p>\n<p>var person = {<\/p>\n<p>    name: &#039;Nicholas&#039;,<\/p>\n<p>    friends: [&#039;Shelby&#039;, &#039;Court&#039;, &#039;Van&#039;]<\/p>\n<p>};<\/p>\n<p>var anotherPerson = createAnother(person);<\/p>\n<p>anotherPerson.sayHi(); \/\/ &#039;hi&#039;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u867d\u7136\u89e3\u51b3\u4e86\u7ed9\u5bf9\u8c61\u6dfb\u52a0\u51fd\u6570\u7684\u95ee\u9898\uff0c\u4f46\u4e0e\u539f\u578b\u5f0f\u7ee7\u627f\u4e00\u6837\uff0c\u5f15\u7528\u7c7b\u578b\u7684\u5c5e\u6027\u4f1a\u88ab\u6240\u6709\u5b9e\u4f8b\u5171\u4eab\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u5bc4\u751f\u7ec4\u5408\u5f0f\u7ee7\u627f<\/h3>\n<\/p>\n<p><p>\u5bc4\u751f\u7ec4\u5408\u5f0f\u7ee7\u627f\u662f\u5bf9\u7ec4\u5408\u7ee7\u627f\u7684\u8fdb\u4e00\u6b65\u4f18\u5316\u3002\u5b83\u901a\u8fc7\u501f\u7528\u6784\u9020\u51fd\u6570\u6765\u7ee7\u627f\u5c5e\u6027\uff0c\u901a\u8fc7\u539f\u578b\u94fe\u7684\u6df7\u6210\u5f62\u5f0f\u6765\u7ee7\u627f\u65b9\u6cd5\u3002\u5176\u80cc\u540e\u7684\u57fa\u672c\u601d\u60f3\u662f\u4e0d\u5fc5\u4e3a\u4e86\u6307\u5b9a\u5b50\u7c7b\u578b\u7684\u539f\u578b\u800c\u8c03\u7528\u8d85\u7c7b\u578b\u7684\u6784\u9020\u51fd\u6570\uff0c\u6211\u4eec\u6240\u9700\u8981\u7684\u65e0\u975e\u5c31\u662f\u8d85\u7c7b\u578b\u539f\u578b\u7684\u4e00\u4e2a\u526f\u672c\u800c\u5df2\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-javascript\">function inheritPrototype(subType, superType){<\/p>\n<p>    var prototype = Object.create(superType.prototype); \/\/ \u521b\u5efa\u5bf9\u8c61<\/p>\n<p>    prototype.constructor = subType; \/\/ \u589e\u5f3a\u5bf9\u8c61<\/p>\n<p>    subType.prototype = prototype; \/\/ \u6307\u5b9a\u5bf9\u8c61<\/p>\n<p>}<\/p>\n<p>function SuperType(name){<\/p>\n<p>    this.name = name;<\/p>\n<p>    this.colors = [&#039;red&#039;, &#039;blue&#039;, &#039;green&#039;];<\/p>\n<p>}<\/p>\n<p>SuperType.prototype.sayName = function(){<\/p>\n<p>    console.log(this.name);<\/p>\n<p>};<\/p>\n<p>function SubType(name, age){<\/p>\n<p>    SuperType.call(this, name);<\/p>\n<p>    this.age = age;<\/p>\n<p>}<\/p>\n<p>inheritPrototype(SubType, SuperType);<\/p>\n<p>SubType.prototype.sayAge = function(){<\/p>\n<p>    console.log(this.age);<\/p>\n<p>};<\/p>\n<p>var instance = new SubType(&#039;Nicholas&#039;, 29);<\/p>\n<p>instance.sayName(); \/\/ Nicholas<\/p>\n<p>instance.sayAge(); \/\/ 29<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5bc4\u751f\u7ec4\u5408\u5f0f\u7ee7\u627f\u662f\u5b9e\u73b0\u57fa\u7c7b\u578b\u7ee7\u627f\u7684\u6700\u6709\u6548\u65b9\u5f0f\u3002\u5b83\u53ea\u8c03\u7528\u4e86\u4e00\u6b21SuperType\u6784\u9020\u51fd\u6570\uff0c\u5e76\u4e14\u907f\u514d\u4e86\u5728SubType.prototype\u4e0a\u521b\u5efa\u4e0d\u5fc5\u8981\u7684\u3001\u591a\u4f59\u7684\u5c5e\u6027\u3002\u4e0e\u6b64\u540c\u65f6\uff0c\u539f\u578b\u94fe\u8fd8\u80fd\u4fdd\u6301\u4e0d\u53d8\uff1b\u56e0\u6b64\uff0c\u8fd8\u80fd\u591f\u6b63\u5e38\u4f7f\u7528instanceof\u548cisPrototypeOf\u3002\u8fd9\u79cd\u6a21\u5f0f\u662f\u76ee\u524d\u5728\u5b9e\u73b0\u7ee7\u627f\u7684\u6700\u7406\u60f3\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. JavaScript\u4e2d\u901a\u8fc7\u539f\u578b\u94fe\u5b9e\u73b0\u7ee7\u627f\u7684\u65b9\u6cd5\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\n\u5728JavaScript\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u539f\u578b\u94fe\u6765\u5b9e\u73b0\u5bf9\u8c61\u4e4b\u95f4\u7684\u7ee7\u627f\u3002\u901a\u8fc7\u5b9a\u4e49\u4e00\u4e2a\u7236\u5bf9\u8c61\u7684\u6784\u9020\u51fd\u6570\uff0c\u5e76\u5c06\u5176\u539f\u578b\u5bf9\u8c61\u8bbe\u7f6e\u4e3a\u4e00\u4e2a\u65b0\u7684\u5b9e\u4f8b\u5bf9\u8c61\uff0c\u7136\u540e\u518d\u901a\u8fc7\u5b50\u5bf9\u8c61\u7684\u6784\u9020\u51fd\u6570\u6765\u521b\u5efa\u65b0\u7684\u5b9e\u4f8b\uff0c\u5b9e\u73b0\u7ee7\u627f\u3002\u5b50\u5bf9\u8c61\u901a\u8fc7\u539f\u578b\u94fe\u7ee7\u627f\u4e86\u7236\u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/p>\n<p><strong>2. JavaScript\u4e2d\u901a\u8fc7\u6784\u9020\u51fd\u6570\u5b9e\u73b0\u7ee7\u627f\u7684\u65b9\u6cd5\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\n\u9664\u4e86\u539f\u578b\u94fe\u7ee7\u627f\u5916\uff0c\u8fd8\u53ef\u4ee5\u5229\u7528\u6784\u9020\u51fd\u6570\u6765\u5b9e\u73b0\u7ee7\u627f\u3002\u5728JavaScript\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728\u5b50\u5bf9\u8c61\u7684\u6784\u9020\u51fd\u6570\u4e2d\u8c03\u7528\u7236\u5bf9\u8c61\u7684\u6784\u9020\u51fd\u6570\uff0c\u4f7f\u7528<code>call<\/code>\u6216<code>apply<\/code>\u65b9\u6cd5\u6765\u5b9e\u73b0\u7ee7\u627f\u3002\u8fd9\u6837\uff0c\u5b50\u5bf9\u8c61\u5c31\u53ef\u4ee5\u7ee7\u627f\u7236\u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/p>\n<p><strong>3. JavaScript\u4e2d\u901a\u8fc7\u6df7\u5408\u7ee7\u627f\u5b9e\u73b0\u7ee7\u627f\u7684\u65b9\u6cd5\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\n\u6df7\u5408\u7ee7\u627f\u662f\u6307\u540c\u65f6\u5229\u7528\u539f\u578b\u94fe\u7ee7\u627f\u548c\u6784\u9020\u51fd\u6570\u7ee7\u627f\u7684\u65b9\u6cd5\u6765\u5b9e\u73b0\u7ee7\u627f\u3002\u901a\u8fc7\u5c06\u7236\u5bf9\u8c61\u7684\u539f\u578b\u5bf9\u8c61\u590d\u5236\u4e00\u4efd\u7ed9\u5b50\u5bf9\u8c61\u7684\u539f\u578b\u5bf9\u8c61\uff0c\u5e76\u8c03\u7528\u7236\u5bf9\u8c61\u7684\u6784\u9020\u51fd\u6570\u6765\u5b9e\u73b0\u7ee7\u627f\u3002\u8fd9\u6837\uff0c\u5b50\u5bf9\u8c61\u65e2\u80fd\u591f\u901a\u8fc7\u539f\u578b\u94fe\u7ee7\u627f\u7236\u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u53c8\u80fd\u591f\u5728\u81ea\u8eab\u7684\u6784\u9020\u51fd\u6570\u4e2d\u5b9a\u4e49\u81ea\u5df1\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u8fd9\u79cd\u7ee7\u627f\u65b9\u6cd5\u53ef\u4ee5\u66f4\u7075\u6d3b\u5730\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728JavaScript\u4e2d\uff0c\u5b9e\u73b0\u7ee7\u627f\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\uff1a\u539f\u578b\u94fe\u7ee7\u627f\u3001\u6784\u9020\u51fd\u6570\u7ee7\u627f\u3001\u7ec4\u5408\u7ee7\u627f\u3001\u539f\u578b\u5f0f\u7ee7\u627f\u3001\u5bc4\u751f\u5f0f\u7ee7\u627f\u3001\u548c [&hellip;]","protected":false},"author":3,"featured_media":154321,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/154316"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=154316"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/154316\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/154321"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=154316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=154316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=154316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}