{"id":183,"date":"2021-02-10T09:59:43","date_gmt":"2021-02-10T01:59:43","guid":{"rendered":"http:\/\/gjweb.top\/?p=183"},"modified":"2021-02-10T09:59:44","modified_gmt":"2021-02-10T01:59:44","slug":"js%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1-%e7%bb%a7%e6%89%bf","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=183","title":{"rendered":"js\u9762\u5411\u5bf9\u8c61 &#8212; \u7ee7\u627f"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u539f\u578b\u7ee7\u627f<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">function Parent(name,age){<br> &nbsp; &nbsp;this.name = name;<br> &nbsp; &nbsp;this.age = age;<br>}<br>Parent.prototype.fun = function(){<br> &nbsp; &nbsp;console.log(\"\u7236\u7ea7\u539f\u578b\" + this.name)<br>}<br>let child1 = new Parent('zs',15);<br>let child2 = new Parent('ls',14);<br>child1.fun() \/\/{name:\"zs\",age:15}<br>child2.fun() \/\/{name:\"ls\",age:14}<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u501f\u7528\u6784\u9020\u51fd\u6570 ( call )<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">function Person(name,age){<br> &nbsp; &nbsp;this.name = name;<br> &nbsp; &nbsp;this.age = age;<br>}<br>\/*\u7ee7\u627f\u6784\u9020\u51fd\u6570\u65f6,\u65e0\u6cd5\u7ee7\u627f\u6784\u9020\u51fd\u6570\u7684\u539f\u578b*\/<br>Person.prototype.fun = function(){<br> &nbsp; &nbsp;console.log(\"\u7236\u7ea7\u539f\u578b\" + this.name)<br>}<br>function Child1(name,age,score){<br> &nbsp; &nbsp;this.score = score;<br> &nbsp; &nbsp;Person.call(this,name,age)<br>}<br>var test1 = new Child1('zs',15,50);<br>var test2 = new Child1('ls',16,90);<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7ec4\u5408\u7ee7\u627f ( \u6784\u9020\u51fd\u6570 + \u539f\u578b\u7ee7\u627f )<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">function Person(name,age){<br> &nbsp; &nbsp;this.name = name,<br> &nbsp; &nbsp;this.age = age<br>}<br>Person.prototype.public = function(){<br> &nbsp; &nbsp;console.log(\"\u7236\u7ea7\u539f\u578b\"+this.name)<br>}<br>function Test(name,age,score){<br> &nbsp; &nbsp;Person.call(this,name,age)<br> &nbsp; &nbsp;this.score = score<br>}<br>Test.prototype = new Person();<br>Test.prototype.constructor = Test;<br>let test = new Test(\"\u5f20\u4e09\",28,100);<br>test.public();<br>console.dir(test);<br>console.log(test);<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u578b\u7ee7\u627f function Parent(name,age){ &nbsp; &nbsp;this.name  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-183","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=183"}],"version-history":[{"count":0,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/183\/revisions"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}