為什么不是Student = Object.create(Person);和Student.prototype = Object.create(Person.prototype);有什么區(qū)別
為什么不是Student = Object.create(Person);和Student.prototype = Object.create(Person.prototype);有什么區(qū)別
為什么不是Student = Object.create(Person);和Student.prototype = Object.create(Person.prototype);有什么區(qū)別
2016-05-18
舉報(bào)
2016-06-27
你可以這樣想,prototype屬性里包含有兩個(gè)屬性,一個(gè)是構(gòu)造器,一個(gè)是實(shí)例原型。當(dāng)你繼承類時(shí),要從父類獲取構(gòu)造器和方法,然而這兩個(gè)都是保存在prototype屬性中。【有誤指出】
2020-04-24
如果用了Student = Object.create(Person),Student 變成了一個(gè)實(shí)例對(duì)象不是一個(gè)構(gòu)造函數(shù)了,
還怎么進(jìn)行下一步new Student()。
2018-04-09
誰(shuí)能再給解釋一下這個(gè)問(wèn)題?
2016-05-18
不太明白,用create創(chuàng)建對(duì)象,Person不就是Student的原型了嗎,為什么還要加prototype
2016-05-18
Student=Object.create(Person)是一個(gè)賦值,表示新建一個(gè)Person對(duì)象賦值給Student,沒(méi)有表現(xiàn)出基于原型鏈的繼承。而后者表示Student的prototype指向原型為Person.prototype的空對(duì)象,這樣才是基于原型鏈的繼承,Student從Person處繼承到了基類的屬性和方法。