为了账号安全,请及时绑定邮箱和手机立即绑定

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创建的实例会发生变化

正在回答

2 回答

constructor是可以随意修改的,一般情况下,构造器A创建的对象的constructor属性就是A(通过A.prototype继承而来)

这里重新设值只是为了迎合这个“习惯”,其实没有太大的意义,因为constructor本就可以随意修改。


0 回复 有任何疑惑可以回复我~
#1

豸题 提问者

非常感谢!
2015-05-08 回复 有任何疑惑可以回复我~

跟我的一模一样,至今不知道怎么解决,你搞定了吗?

udlomwaupl

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

Student.prototype.constructor = Student

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信