I have a object like this:
myobj={
//where to define Car car=new Car();
test:{
testFunc1(){car.paintTest();},
testFunc2(){car.drawTest();}
},
use:{
useFunc1(){car.paintUse();},
useFunc2(){car.drawUse();}
},
};
I will use myobj in the way that, in another js file, I can easily call
myobj.test.testFunc2();
or
myobj.use.useFunc1();
As you notice, in myobj, I have a car instance frequently be used in different functions in different sub-objects (e.g. “test”, “use” sub-objects).
I am wondering, where can I define Car car=new Car(); in myobj so that the car is defined once and can be used in several functions in myobj.
you can do that like this:
UPDATE
working version with fake
Carobject:fiddle: http://jsfiddle.net/maniator/KcQvL/