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