Good afternoon, I am playing a little in javascript and I have a "class" of this form:
var Card = function(url,c){
...
this.img = new Image();
this.widthCurr = 0;
this.heightCurr = 0;
this.img.onload = this.imageLoaded()
this.img.src = this.url;
};
and a method defined as
Card.prototype = {
imageLoaded : function(){
//my goal is to initialize this.widthCurr and this.heightCurr
console.log(this.img.width);
},
...
};
Basically my goal is to initialize widthCurr and heightCurr with actual width and height of img, when the img is loaded. I created new object and console.log command in imageLoaded keeps saying "0" so at that time, image is not loaded. I tried a few modifications, but no one seemed to work. Am I missing something important? How or where should I set these values?