XManBG
11-16-2013, 09:53 PM
Hi guys,
there is a roughly Background object definition with 4 layers like:
function Background(){
this.layer1 = new Layer(1);
this.layer2 = new Layer(2);
this.layer3 = new Layer(3);
this.layer4 = new Layer(4);
}
function Layer(number){
this.number = number;
this.image = ''; // Image file name is empty for now, I'd like to fill it out appropriate later
... more misc stuff ...
}
Let's say I'd like to define an additional method to the object Background, which takes a layer and does something to it, i.e. add a picture to the layer.
I've tried with following definition without success; FF25 did it, but IE10 crashes every time?!
function Background(){
this.layer1 = new Layer(1);
this.layer2 = new Layer(2);
this.layer3 = new Layer(3);
this.layer4 = new Layer(4);
this.addimage = function(layer){
layer.image = 'picture' + layer.number + '.jpg';
}
}
...
// ... and now I'd like to use my method
var background = new Background();
background.addimage(background.layer1);
Is there an error?!
there is a roughly Background object definition with 4 layers like:
function Background(){
this.layer1 = new Layer(1);
this.layer2 = new Layer(2);
this.layer3 = new Layer(3);
this.layer4 = new Layer(4);
}
function Layer(number){
this.number = number;
this.image = ''; // Image file name is empty for now, I'd like to fill it out appropriate later
... more misc stuff ...
}
Let's say I'd like to define an additional method to the object Background, which takes a layer and does something to it, i.e. add a picture to the layer.
I've tried with following definition without success; FF25 did it, but IE10 crashes every time?!
function Background(){
this.layer1 = new Layer(1);
this.layer2 = new Layer(2);
this.layer3 = new Layer(3);
this.layer4 = new Layer(4);
this.addimage = function(layer){
layer.image = 'picture' + layer.number + '.jpg';
}
}
...
// ... and now I'd like to use my method
var background = new Background();
background.addimage(background.layer1);
Is there an error?!