小编Ray*_*den的帖子

JavaScript 保存这个。image.onLoad 中的变量

function InfoImage(path,title){
    this.path = path;
    this.title = title;
    this.color = undefined;
    this.maxPixels = undefined;

    this.init = function(){
        var canvas = document.querySelector("canvas");
        var img_Color = new Image_Processing_Color(canvas);
        var img = new Image();
        img.onload = function () {
            img_Color.init(img);
            this.color = img_Color.getDominantColor(); //this doesnt work
            this.maxPixels = img_Color.getDominantColorPixels();
        };
        img.src = path;
    };


    this.init();
}
Run Code Online (Sandbox Code Playgroud)

在这个例子中,我如何将这些变量保存为 InfoImage 变量?我知道在this那里使用会影响 Image 而不是 InfoImage ...

javascript object

3
推荐指数
1
解决办法
2484
查看次数

标签 统计

javascript ×1

object ×1