Action in Timer without quotes.

Hi,
I’m trying to make a timer with a recursion, which belongs to objectX. timer_with_recursion fires successfully, after it has been called by another_function . But there are some problems with timer. If i do not enclose the action in quotes, it fires again and again without any delay.

objectX.addProperties({
	timer_with_recursion: function () {
		alert('start!');
		isc.Timer.setTimeout(this.timer_with_recursion(),10000);
	},
	another_function: function () {
		...
		...
		this.timer_with_recursion();
	}
});

But if I the action is enclosed, an error occurs “this.timer_with_recursion is not a function [Break on this error] isc.$aq=function(_1,_2){var _3=_2||_1;re…;isc.$at[isc.$at.length]=_1;return null}” ISC_Core.js (line 63), after timer_with_recursion fires successfully, called by another_function

objectX.addProperties({
	timer_with_recursion: function () {
		alert('start!');
		isc.Timer.setTimeout("this.timer_with_recursion()",10000);
	},
	another_function: function () {
		...
		...
		this.timer_with_recursion();
	}
});

Please can you help me ?

By adding parens (that is, “()”) at the end of the function name, you are actually executing the function yourself, and what you are actually passing to setTimeout is the return value of the function. Either quote the function with parents (in which case you are passing a string), or pass the function without adding parens (in which case you are passing the Function as such).

Thanks. Now it fires twice. Can something break a recursion?

objectX.addProperties({
	timer_with_recursion: function () {
		alert('start!');
		isc.Timer.setTimeout(this.timer_with_recursion,10000);
	},
	another_function: function () {
		...
		...
		this.timer_with_recursion();
	}
});

You should invest in a good book on JavaScript, because you’re having trouble with basic JavaScript issues of scope. Your issue now is that ‘this’ has different meaning when your timer in invoked - you have passed only the function to setTimeout, not an object to invoke the function on. See the dogs for Callback as well. Best of luck.

Thanks for the help and patience. :slight_smile: I made it.

objectX.addProperties({
	timer_with_recursion: function () {
		alert('start!');
		thisObj = this;
		setTimeout(function() {thisObj.timer_with_recursion.call(thisObj);}, 10000);
	},
	another_function: function () {
		...
		...
		this.timer_with_recursion();
	}
});