在extjs4.2;
在以下代码中,显示" Uncaught ReferenceError:config未定义"在chrome的控制台上。
可能是问题所在 Vehicle.prototype.constructor.call(此,配置); 但是,为什么它无法通过配置。
为什么呢? 有人能帮助我吗?
谢谢。
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());
答案 0 :(得分:0)
您缺少的是构造函数的参数。
我做了一个小提琴来表示你:http://jsfiddle.net/edhedges/JkPLL/
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(config){ // missing config here
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());