gpt4 book ai didi

javascript - 在 JavaScript 中调用函数时自定义

转载 作者:行者123 更新时间:2023-11-30 13:14:59 24 4
gpt4 key购买 nike

<分区>

这是我目前拥有的:http://jsfiddle.net/nxCFn/

var il = new ImageLoader();

function ImageLoader() {
this.n = 2;

this.load = function() {
//obviously, the this = the image and not the original instance of ImageLoader :(
this.n++;
console.log(this.n);
}

this.imgnam = "http://www.google.com/images/errors/logo_sm.gif";

this.img = new Image();
this.img.src = this.imgnam;
this.img.onload = this.load;
}​

因为图像正在调用 .load() thisload 指向图像。我想让 this 从加载点到它“属于”的 ImageLoader 实例。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com