Posted By

eden159 on 01/08/09


javascript class object

Versions (?)

Last Edited at 01/08/09 07:18am

Viewed 0 times

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

/ Published in: JavaScript


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:

  1. thisObj = this;
  2. setTimeout(function() { thisObj.methodToCall(); }, time);

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.