Let\'s assume that I have the timeout ID returned from setTimeout
or setInterval
.
Can I get, in some way, the original function or code, as
the IDs returned from setTimeout
/setInterval
are just numbers, they have no properties or methods other than those that every other number would have. If you want to get that function, you can declare it first instead of using an anonymous:
var myFunc = function() {
console.log('Hello Stackoverflowers!');
};
var timer_id = setTimeout(myFunc, 100000);
myFunc(); // output: 'Hello Stackoverflowers!'
clearTimeout(timer_id); // unless you want it to fire twice