Student.prototype.constructor = Student
如果不顯示的將constructor 設置為Student,那么下一次
當出于實現繼承的目的而修改了構造器Student.prototype時,Student.prototype.constructor已經不是Student了,為了避免誤解,手動重設Student.prototype.constructor屬性,這樣通過new Student創建的實例的constructor又可以正確取到Student了?引用問題鏈接
對這段話不理解,老師能否用一個例子解釋一下,怎樣修改構造器Student.prototype 之后,并且也沒有顯示重設Student.prototype.constructor,那么通過new Student創建的實例會發生變化
2015-05-08
constructor是可以隨意修改的,一般情況下,構造器A創建的對象的constructor屬性就是A(通過A.prototype繼承而來)
這里重新設值只是為了迎合這個“習慣”,其實沒有太大的意義,因為constructor本就可以隨意修改。