Skip to main content

Set variable within another context



I have the following function







"use strict";

function Player

{

this.width;

this.height;

this.framesA = 5;



this.image = new Image();

this.image.onload = function ()

{

width = this.width;

height = this.height / framesA;

}

this.image.src = "Images/angel.png";

}







How can I make this code to work?


I want the width and height in the Player function be inalized with the width and the height of the image when the onload function is called.





I need this to work with strict mode (A must).





If this should be accomplished another way feel free to teach.





EDIT: I updated the code to reflect a more realistic situation(I didn't know this will be so complicated)





EDIT 2: Another update to the code. I didn't notice that I wrote var insted of this. Sorry.





Thanks in advance


Comments

Popular posts from this blog

Wildcards in a hosts file

I want to setup my local development machine so that any requests for *.local are redirected to localhost . The idea is that as I develop multiple sites, I can just add vhosts to Apache called site1.local , site2.local etc, and have them all resolve to localhost , while Apache serves a different site accordingly.