PDA

View Full Version : Extend's Constructor can't find config parm?



softball
17 Jun 2014, 12:37 AM
Dear:
In the follow code?It's show "Uncaught ReferenceError: config is not defined " on chrome's console.
why?

thx



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());

softball
18 Jun 2014, 6:59 PM
I get It: constructor:function(){ no config been included . constructor:function(config){ ?will be oK