Is there a way I can refer to the class object, in the image.onload?
this
refers to the image itself. How I can refer to the Texture object?
https://jsfiddle.net/yL648t40/
function Texture(url){
this.image = new Image();
this.image.src = url;
this.image.onload = function(){
this.width = this.image.width;
this.height = this.image.height;
}
}
text = new Texture("http://opengameart.org/sites/default/files/styles/watermarked/public/bone2-equus_hemionus.png");
document.body.innerHTML += text.image + "<br>";
document.body.innerHTML += text.image.src + "<br>";
document.body.innerHTML += text.image.width + "<br>";
I've tried using something like this inside the Texture class
self = this;
this.image.onload = function(self){
self.width = self.image.width;
self.height = self.image.height;
}
But obiviously it doesn't work