{"id":12962,"date":"2023-11-29T10:11:51","date_gmt":"2023-11-29T02:11:51","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=12962"},"modified":"2023-11-29T10:11:55","modified_gmt":"2023-11-29T02:11:55","slug":"qian-duan-mian-shi-tijs-zhong-shen-me-shi-lei","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/29\/qian-duan-mian-shi-tijs-zhong-shen-me-shi-lei\/","title":{"rendered":"\u524d\u7aef\u9762\u8bd5\u9898\uff1aJS\u4e2d\u4ec0\u4e48\u662f\u7c7b\uff1f"},"content":{"rendered":"<p>\u7c7b(class)\u662f\u5728JS\u4e2d\u7f16\u5199\u6784\u9020\u51fd\u6570\u7684\u65b0\u65b9\u6cd5\u3002\u5b83\u662f\u4f7f\u7528\u6784\u9020\u51fd\u6570\u7684\u8bed\u6cd5\u7cd6\uff0c\u5728\u5e95\u5c42\u4e2d\u4f7f\u7528\u4ecd \u7136\u662f\u539f\u578b\u548c\u57fa\u4e8e\u539f\u578b\u7684\u7ee7\u627f\u3002<br \/>\n\/\/ES5 Version<br \/>\nfunction Person(firstName, lastName, age, address) {<br \/>\nthis. firstName = firstName\uff1b<br \/>\nthis. lastName = lastName\uff1b<br \/>\nthis.age = age\uff1b<br \/>\nthis. address = address\uff1b<br \/>\n}<br \/>\nPerson. self = function() {<br \/>\nreturn this\uff1b<br \/>\n}<br \/>\nPerson. prototype. toString = function () {<br \/>\nreturn &quot;[object Person]&quot;\uff1b<br \/>\n}<br \/>\nPerson, prototype. getFullName = function (){<br \/>\nreturn this. firstName + &quot; &quot; + this. lastName\uff1b<br \/>\n}<br \/>\n\/\/ES6 Version<br \/>\nclass Person {<br \/>\nconstructor(firstName, lastName, age, address) {<br \/>\nthis. lastName = lastName\uff1b<br \/>\nthis. firstName = firstName\uff1b<br \/>\nthis. age = age\uff1b<br \/>\nthis. address = address\uff1b<br \/>\n}<br \/>\nstatic self() {<br \/>\nreturn this\uff1b<br \/>\n}<br \/>\ntoString () {<br \/>\nreturn &quot;[object Person]&quot;;<br \/>\n}<br \/>\ngetFullName(){<br \/>\nreturn <code><span class=\"katex math inline\">{this. firstName} <\/span>{this. lastName}<\/code>\uff1b<br \/>\n}<br \/>\n}<br \/>\n\u91cd\u5199\u65b9\u6cd5\u5e76\u4ece\u53e6\u4e00\u4e2a\u7c7b\u7ee7\u627f\u3002<br \/>\n\/\/ES5 Version<br \/>\nEmployee.prototype = Object.create (Person. prototype);<br \/>\nfunction Employee(firstName, lastName, age, address, jobTitle, yearStarted) {<br \/>\nPerson. call (this, firstName, lastName, age, address)\uff1b<br \/>\nthis.jobTitle = jobTitle\uff1b<br \/>\nthis. yearStarted = yearStarted;<br \/>\n}<br \/>\nEmployee. prototype. describe = function () {<br \/>\nreturn I am <span class=\"katex math inline\">{this. getFulIName ()} and I have a position of<\/span> {this. jobTitle} and I started at<br \/>\n<code>${this. yearStarted}<\/code>\uff1b<br \/>\n}<br \/>\nEmployee. prototype. toString = function () {<br \/>\nreturn &quot;[object Employee]&quot;;<br \/>\n}<br \/>\n\/\/ES6 Version<br \/>\nclass Employee extends Person { \/\/Inherits from &quot;Person&quot; class<br \/>\nconstruetor(firstName, lastName, age, address, jobTitle, yearStarted) {<br \/>\nsuper(firstName, lastName, age, address)\uff1b<br \/>\nthis. jobTitle = jobTitle\uff1b<br \/>\nthis. yearStarted = yearStarted\uff1b<br \/>\n}<br \/>\ndescribe () {<br \/>\nreturn I am <span class=\"katex math inline\">{this. getFulIName()} and I have a position of<\/span>{this. jobTitle} and I started at ${this. yearStarted}\uff1b<br \/>\n}<br \/>\ntoString() { \/\/ Overriding the &quot;toString&quot; method of &quot;Person&quot;<br \/>\nreturn &quot;[object Employee]&quot;\uff1b<br \/>\n}<br \/>\n}<br \/>\n\u6240\u4ee5\u6211\u4eec\u8981\u600e\u4e48\u77e5\u9053\u5b83\u5728\u5185\u90e8\u4f7f\u7528\u539f\u578b\uff1f<br \/>\nclass Something {<br \/>\n}<br \/>\nfunction AnotherSomething() {<br \/>\n}<br \/>\nconst as = new AnotherSomething()\uff1b<br \/>\nconst s = new Something()\uff1b<br \/>\nconsole. log(typeof Something)\uff1b \/\/ &quot;function&quot;<br \/>\nconsole. log(typeof AnotherSomething)\uff1b \/\/ &quot;function&quot;<br \/>\nconsole. log (as. toString()) \uff1b \/\/ &quot; [object Object]&quot;<br \/>\nconsole. log (as. toString()) \uff1b \/\/ &quot; [object Object]&quot;<br \/>\nconsole. log(as. toString = Object, prototype. toString)\uff1b \/\/ true<br \/>\nconsole. log(s. toString = Object, prototype. toString) \uff1b \/\/ true<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7c7b(class)\u662f\u5728JS\u4e2d\u7f16\u5199\u6784\u9020\u51fd\u6570\u7684\u65b0\u65b9\u6cd5\u3002\u5b83\u662f\u4f7f\u7528\u6784\u9020\u51fd\u6570\u7684\u8bed\u6cd5\u7cd6\uff0c\u5728\u5e95\u5c42\u4e2d\u4f7f\u7528\u4ecd \u7136\u662f\u539f\u578b\u548c\u57fa\u4e8e\u539f\u578b\u7684 [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[103],"tags":[],"class_list":["post-12962","post","type-post","status-publish","format-standard","hentry","category-qianduan"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12962","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=12962"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12962\/revisions"}],"predecessor-version":[{"id":12963,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12962\/revisions\/12963"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=12962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=12962"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=12962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}