javascript - variable is set to undefined in function -
this question has answer here: how use “settimeout” invoke object itself 3 answers i trying create slide show load next slide before current 1 done. have 2 prototypes this. 1 showing current slide , 1 loading next slide. it worked fine until put settimeout() delay between slides. nextslide() function calling after settimeout() this.nextslide undefined if it's loaded , added this.nextslide in loadnextslide() . $(document).ready(function(){ //set width , height of canvas var width = $(document).width(); var height = $(document).height(); $("#mkslide").css({"width":width+"px","height":height+"px"}); slideshow = new slideshow(width, height, "2d"); slideshow.loadnextslide(null); slideshow.nextslide(); }); function slideshow(canvaswidth, canvasheight, dimension){ //c...