{"id":3324,"date":"2024-11-10T13:26:53","date_gmt":"2024-11-10T05:26:53","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3324\/"},"modified":"2024-11-10T13:26:53","modified_gmt":"2024-11-10T05:26:53","slug":"%e5%8e%9f%e7%94%9fjs%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e7%bb%a7%e6%89%bf","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3324\/","title":{"rendered":"\u539f\u751fjs\u5982\u4f55\u5b9e\u73b0\u7ee7\u627f"},"content":{"rendered":"<blockquote><p>\n  javascript \u901a\u8fc7\u539f\u578b\u94fe\u548c\u6784\u9020\u51fd\u6570\u5b9e\u73b0\u7ee7\u627f\u3002\u4f7f\u7528\u539f\u578b\u94fe\uff0c\u7236\u5bf9\u8c61\u4f5c\u4e3a\u5b50\u5bf9\u8c61\u7684\u539f\u578b\uff0c\u5b50\u5bf9\u8c61\u7ee7\u627f\u7236\u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u4f7f\u7528\u6784\u9020\u51fd\u6570\uff0c\u5b50\u6784\u9020\u51fd\u6570\u5c06\u7236\u6784\u9020\u51fd\u6570\u4f5c\u4e3a\u539f\u578b\uff0c\u5e76\u901a\u8fc7\u8986\u76d6\u7236\u7c7b\u65b9\u6cd5\u5b9e\u73b0\u5b9a\u5236\u5316\u3002\u672c\u4f8b\u4e2d\uff0cperson \u662f\u7236\u7c7b\uff0cemployee \u662f\u5b50\u7c7b\uff0cemployee \u7ee7\u627f\u4e86 person \u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u5e76\u6dfb\u52a0\u4e86\u81ea\u5df1\u7684 sayjob \u65b9\u6cd5\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110809452212599.jpg\" class=\"aligncenter\" title=\"\u539f\u751fjs\u5982\u4f55\u5b9e\u73b0\u7ee7\u627f\u63d2\u56fe\" alt=\"\u539f\u751fjs\u5982\u4f55\u5b9e\u73b0\u7ee7\u627f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728\u539f\u751f JavaScript \u4e2d\u5b9e\u73b0\u7ee7\u627f<\/strong><\/p>\n<p>JavaScript \u662f\u4e00\u79cd\u57fa\u4e8e\u539f\u578b\u94fe\u7684\u8bed\u8a00\uff0c\u5b83\u4e0d\u76f4\u63a5\u652f\u6301\u7c7b\u548c\u7ee7\u627f\uff0c\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u539f\u578b\u94fe\u548c\u6784\u9020\u51fd\u6570\u6765\u6a21\u62df\u7ee7\u627f\u3002<\/p>\n<p><strong>\u4f7f\u7528\u539f\u578b\u94fe\u5b9e\u73b0\u7ee7\u627f<\/strong><\/p>\n<ol>\n<li> <strong>\u521b\u5efa\u7236\u5bf9\u8c61\uff1a<\/strong>\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u4f5c\u4e3a\u7236\u5bf9\u8c61\uff0c\u5b83\u5305\u542b\u8981\u7ee7\u627f\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/li>\n<\/ol>\n<pre>const Parent = {\n  name: \"Parent\",\n  sayName() {\n    console.log(this.name);\n  }\n};<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li> <strong>\u521b\u5efa\u5b50\u5bf9\u8c61\uff1a<\/strong>\u521b\u5efa\u5b50\u5bf9\u8c61\uff0c\u5c06\u7236\u5bf9\u8c61\u7684\u539f\u578b\u94fe\u8bbe\u7f6e\u4e3a\u5176\u539f\u578b\u3002<\/li>\n<\/ol>\n<pre>const Child = Object.create(Parent);\nChild.name = \"Child\";<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u4f7f\u7528\u6784\u9020\u51fd\u6570\u5b9e\u73b0\u7ee7\u627f<\/strong><\/p>\n<ol>\n<li> <strong>\u521b\u5efa\u7236\u6784\u9020\u51fd\u6570\uff1a<\/strong>\u521b\u5efa\u4e00\u4e2a\u7236\u6784\u9020\u51fd\u6570\uff0c\u5b83\u5305\u542b\u8981\u7ee7\u627f\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/li>\n<\/ol>\n<pre>function Parent(name) {\n  this.name = name;\n}\n\nParent.prototype.sayName = function() {\n  console.log(this.name);\n};<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li> <strong>\u521b\u5efa\u5b50\u6784\u9020\u51fd\u6570\uff1a<\/strong>\u521b\u5efa\u5b50\u6784\u9020\u51fd\u6570\uff0c\u5c06\u7236\u6784\u9020\u51fd\u6570\u4f5c\u4e3a\u5176\u539f\u578b\u3002<\/li>\n<\/ol>\n<pre>function Child(name) {\n  Parent.call(this, name);\n}\n\nChild.prototype = Object.create(Parent.prototype);\nChild.prototype.constructor = Child;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u5728\u5b50\u7c7b\u4e2d\u8986\u76d6\u7236\u7c7b\u65b9\u6cd5<\/strong><\/p>\n<p>\u8981\u8986\u76d6\u7236\u7c7b\u4e2d\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5728\u5b50\u7c7b\u7684\u539f\u578b\u94fe\u4e2d\u91cd\u65b0\u5b9a\u4e49\u8be5\u65b9\u6cd5\u3002<\/p>\n<pre>Child.prototype.sayName = function() {\n  console.log(\"Child: \" + this.name);\n};<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528\u6784\u9020\u51fd\u6570\u5b9e\u73b0\u7ee7\u627f\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>function Person(name) {\n  this.name = name;\n}\n\nPerson.prototype.sayName = function() {\n  console.log(this.name);\n};\n\nfunction Employee(name, title) {\n  Person.call(this, name);\n  this.title = title;\n}\n\nEmployee.prototype = Object.create(Person.prototype);\nEmployee.prototype.constructor = Employee;\n\nEmployee.prototype.sayJob = function() {\n  console.log(this.name + \" is a \" + this.title);\n};\n\nconst john = new Employee(\"John\", \"Software Engineer\");\njohn.sayName(); \/\/ \u8f93\u51fa\uff1a\"John\"\njohn.sayJob(); \/\/ \u8f93\u51fa\uff1a\"John is a Software Engineer\"<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u539f\u751fjs\u5982\u4f55\u5b9e\u73b0\u7ee7\u627f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>javascript \u901a\u8fc7\u539f\u578b\u94fe\u548c\u6784\u9020\u51fd\u6570\u5b9e\u73b0\u7ee7\u627f\u3002\u4f7f\u7528\u539f\u578b\u94fe\uff0c\u7236\u5bf9\u8c61\u4f5c\u4e3a\u5b50\u5bf9\u8c61\u7684\u539f\u578b\uff0c\u5b50\u5bf9\u8c61\u7ee7\u627f\u7236\u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u4f7f\u7528\u6784\u9020\u51fd\u6570\uff0c\u5b50\u6784\u9020\u51fd\u6570\u5c06\u7236\u6784\u9020\u51fd\u6570\u4f5c\u4e3a\u539f\u578b\uff0c\u5e76\u901a\u8fc7\u8986\u76d6\u7236\u7c7b\u65b9\u6cd5\u5b9e\u73b0\u5b9a\u5236\u5316\u3002\u672c\u4f8b\u4e2d\uff0cperson \u662f\u7236\u7c7b\uff0cemployee \u662f\u5b50\u7c7b\uff0cemployee \u7ee7\u627f\u4e86 person \u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u5e76\u6dfb\u52a0\u4e86\u81ea\u5df1\u7684 sayjob \u65b9\u6cd5\u3002 \u5728\u539f\u751f JavaScript \u4e2d\u5b9e\u73b0\u7ee7\u627f JavaScript \u662f\u4e00\u79cd\u57fa\u4e8e\u539f\u578b\u94fe\u7684\u8bed\u8a00\uff0c\u5b83\u4e0d\u76f4\u63a5\u652f\u6301\u7c7b\u548c\u7ee7\u627f\uff0c\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u539f\u578b\u94fe\u548c\u6784\u9020\u51fd\u6570\u6765\u6a21\u62df\u7ee7\u627f\u3002 \u4f7f\u7528\u539f\u578b\u94fe\u5b9e\u73b0\u7ee7\u627f \u521b\u5efa\u7236\u5bf9\u8c61\uff1a\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u4f5c\u4e3a\u7236\u5bf9\u8c61\uff0c\u5b83\u5305\u542b\u8981\u7ee7\u627f\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002 const Parent = { name: &#8220;Parent&#8221;, sayName() { console.log(this.name); } }; \u767b\u5f55\u540e\u590d\u5236 \u521b\u5efa\u5b50\u5bf9\u8c61\uff1a\u521b\u5efa\u5b50\u5bf9\u8c61\uff0c\u5c06\u7236\u5bf9\u8c61\u7684\u539f\u578b\u94fe\u8bbe\u7f6e\u4e3a\u5176\u539f\u578b\u3002 const Child = Object.create(Parent); Child.name = &#8220;Child&#8221;; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u6784\u9020\u51fd\u6570\u5b9e\u73b0\u7ee7\u627f \u521b\u5efa\u7236\u6784\u9020\u51fd\u6570\uff1a\u521b\u5efa\u4e00\u4e2a\u7236\u6784\u9020\u51fd\u6570\uff0c\u5b83\u5305\u542b\u8981\u7ee7\u627f\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002 function Parent(name) { this.name = name; } Parent.prototype.sayName = function() { console.log(this.name); }; \u767b\u5f55\u540e\u590d\u5236 \u521b\u5efa\u5b50\u6784\u9020\u51fd\u6570\uff1a\u521b\u5efa\u5b50\u6784\u9020\u51fd\u6570\uff0c\u5c06\u7236\u6784\u9020\u51fd\u6570\u4f5c\u4e3a\u5176\u539f\u578b\u3002 function [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3324","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3324"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3324\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}