在extjs4.2中;Extend的构造函数找不到配置参数?
在下面的代码中,它在chrome的控制台上显示“Uncaught ReferenceError:config is not defined”。
这可能是 中的问题Vehicle.prototype.constructor.call(this,config); 但是,为什么它不能通过配置。
为什么? 有人可以帮助我吗?
谢谢。
function Vehicle(config){
this.x=config.x;
this.y=config.y;
}
Vehicle.prototype.move=function(dx,dy){
this.x +=dx;
this.y +=dy;
};
Vehicle.prototype.toString=function(){
return "point:"+x+","+y;
};
var Car=Ext.extend(Vehicle,{
constructor:function(){
Vehicle.prototype.constructor.call(this,config);
this.color=config.color;
},move:function(dx){
this.x=dx;
},toString:function(){
var str="Car is "+ this.x + " miles away from the origial position.";
str +=" this car is :"+this.colr;
return str;
}
});
var carConfig={
x:10,
y:0,
color:"white"
};
var car= new Car(carConfig);
car.move(150);
console.info(car.toString());
你可以做一个小提琴? – edhedges
你为什么要写这样的课程? Ext提供了一个完整的类系统来抽象出很多这样的东西。 –