mardi 17 juin 2014

Extend's Constructor can't find config parm?

Dear:

In the follow code,It's show "Uncaught ReferenceError: config is not defined " on chrome's console.

why?

thx



Code:



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




Aucun commentaire:

Enregistrer un commentaire