在 Javascript 中的类中加载图像时,如何让回调成为类的方法而不是全局方法?
tc = new TestClass();
var TestClass = function(){
var img = new Image();
img.src = 'mars.png';
img.onLoad = this.imagesHasLoaded(); //does not work,
//uncaught TypeError: Object [object Object] has no method 'imagesHasLoaded' ....js:28
img.onLoad = imageLoaded(); //Works, logs yes, its loaded
function imageLoaded(){
console.log("yes, its loaded");
}
this.imagesHasLoaded = function(){
console.log("loaded happened");
}
function isLoaded(){
trace("loaded happened");
}
}