浏览器图片预加载的时候,用到了Image这个类:var img=new Image();
img.src="http://xxxxx";但是Image类跟我们自己建立的类不太一样,它是一个function没错,可是却没有prototype属性:alert("typeof Image:"+typeof Image+"\n"+"Image.prototype:"+Image.prototype);
/*display
typeof Image:function
Image.prototype:undefined
*/这个虽然不重要,但是当我想给Image的原型建立方法的时候,就出现问题了//Image.prototype.show=function(x){this.src=x;};//这种用法是错的,因为Image没有prototype对象
Image.prototype={
show:function(x){this.src=x;}
};//硬上弓,添加prototype对象
window.onload=function(){
var img=new Image();
document.lastChild.lastChild.appendChild(img);
img.show("http://xxxxxx");//给img添加的show方法,替代img.src属性,测试的时候通不过
alert(img.show);//undefined
};Image既然没有prototype属性,我加了它,可是在用new新建实例后,实例却没有原型中的show方法,很奇怪,不是吗?谁能解释下。