有人能解释一下为什么javascript中的这种固有特性不起作用吗?
那么为什么子类没有变量呢?我认为这就是原型设计的全部要点。您只是将对有人能解释一下为什么javascript中的这种固有特性不起作用吗?,javascript,oop,inheritance,Javascript,Oop,Inheritance,那么为什么子类没有变量呢?我认为这就是原型设计的全部要点。您只是将对超类的引用构造函数分配给子类。prototype,您需要使用new操作符使这个子类。prototype对象成为超类的实例: This is a sub class with name Sub and variable undefined //... SubClass.prototype = new SuperClass(); //.. 您可能希望在上行之后恢复子类.prototype对象的构造函数属性,因为如果不这样做,则使
超类的引用构造函数分配给子类。prototype
,您需要使用new
操作符使这个子类。prototype
对象成为超类的实例:
This is a sub class with name Sub and variable undefined
//...
SubClass.prototype = new SuperClass();
//..
您可能希望在上行之后恢复子类.prototype
对象的构造函数
属性,因为如果不这样做,则使用子类
创建的实例(如示例中的子
)将有一个继承的构造函数
属性错误地指向超类
:
This is a sub class with name Sub and variable undefined
//...
SubClass.prototype = new SuperClass();
//..
检查一个例子
推荐文章: