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