我试图弄清楚如何使用原型对象获取多个图像对象。我知道我可以得到一个图像的一个实例。但我想从一个数组中声明多个图像,然后能够用它们创建一个实例。下面是我的代码片段。任何帮助会很高兴..谢谢:)
function SuperType(name){
this.name = name;
this.pictures = new Array();
this.pictures = new Image();
this.pictures[0].src = ["Desert.jpg"];
this.pictures = new Image();
this.pictures[1].src = ["Storm.jpg"];
}
SuperType.prototype.sayName = function(){
alert(this.name);
};
function SubType(name, age){
SuperType.call(this, name);
this.age = age;
}
SubType.prototype = new SuperType();
SubType.prototype.sayAge = function(){
alert(this.age);
};
var instance1 = new SubType("Nicholas", 29);
document.getElementById("id0").appendChild(instance1.pictures[0])
document.getElementById("id1").appendChild(instance1.pictures[1])