I have a "class" defined:
function Car(door, engine) {
this.door = door;
this.engine = engine;
function setDoor(door) {
this.door = door;
}
function getDoor(door) {
return door;
}
function setEngine(engine) {
return engine;
}
function getEngine() {
return engine;
}
}
I want to extract data from an object in javascript, in the same file I have another "class" and the function to add.
function bodyCar(car) {
newCar = new Array();
function addCar(car) {
newCar = car.door;
newCar = car.engine;
return "The new car have " + car.door + " doors. engine " + car.engine;
}
}
the call to the class and function:
var myCar = new bodyCar();
myCar.addCar(new Car(5,"2200cc"));
document.write(myCar);
But it does not work for me. It gives a type error "myCar.addCar is not a function".
thanks for your help.
newCar = new Array(), but then you assigncar.doorandcar.engineto the array inaddCar?addCar()is a local function inbodyCarbodyCarshare the samenewCar.