Javascript图像onload回调类intern函数

Javascript图像onload回调类intern函数,javascript,image,callback,onload,Javascript,Image,Callback,Onload,我的问题是“this”在“onload=function()”-函数中无效 警惕(“!”);执行,但不执行Objekt.prototype.autoSize()函数,例如 调用我的“class intern”函数(如autoSize)时,我必须做些什么?这是因为当对象作为接收器时,不会调用onload函数。因此,这个,在这个回调中,不是所需的对象 您可以执行此操作以将此传输到onload回调: Objekt.prototype.loadImg = function(pImg){ if(p

我的问题是“this”在“onload=function()”-函数中无效

警惕(“!”);执行,但不执行Objekt.prototype.autoSize()函数,例如


调用我的“class intern”函数(如autoSize)时,我必须做些什么?

这是因为当对象作为接收器时,不会调用
onload
函数。因此,
这个
,在这个回调中,不是所需的对象

您可以执行此操作以将
传输到
onload
回调:

Objekt.prototype.loadImg = function(pImg){
    if(pImg!=null){
        this.imgLoaded=false;
        this.img = null;
        this.img = new Image();         
        this.img.src = pImg;     
        this.img.onload = function(){
            alert("!");
            this.autoSize();                
            this.imgLoaded=true;
        }; 

    }
}

这是因为当对象作为接收器时,不会调用
onload
函数。因此,
这个
,在这个回调中,不是所需的对象

您可以执行此操作以将
传输到
onload
回调:

Objekt.prototype.loadImg = function(pImg){
    if(pImg!=null){
        this.imgLoaded=false;
        this.img = null;
        this.img = new Image();         
        this.img.src = pImg;     
        this.img.onload = function(){
            alert("!");
            this.autoSize();                
            this.imgLoaded=true;
        }; 

    }
}

完美的非常感谢你!完美的非常感谢你!