Return to Snippet

Revision: 10659
at January 8, 2009 07:18 by eden159


Initial Code
thisObj = this;
setTimeout(function() { thisObj.methodToCall(); }, time);

Initial URL
http://www.klevo.sk/javascript/javascripts-settimeout-and-how-to-use-it-with-your-methods/

Initial Description
Everything works as expected for the setTimeout() function until you try to call a method inside your ‘class’ (there are no real classes in JavaScript). Something like this won’t work:

setTimeout(this.methodToCall, time);
Passing a string representation instead of reference doesn’t work either.

So here is the simple solution:

Initial Title
JavaScript’s setTimeout and how to use it with your methods

Initial Tags
javascript, class, object

Initial Language
JavaScript