Reputation: 547
(function($)
{
$.fn.myPlugin = function(options)
{
var _this;
var timer1;
var foo = function(n)
{
if (timer1 != null) return; // in action
timer1 = setInterval("bar("+n+")", 500);
};
var bar = function(n)
{
...
if ( ... ) clearInterval(timer1);
};
return this.each(function()
{
_this = $(this);
_this.bind("click", function(){ foo(10); });
});
}
})(jQuery);
This doesn't work because "bar is not defined."
Upvotes: 0
Views: 186
Reputation: 630559
Instead of a string, you need to pass a function which directly references bar
, so instead of this:
setInterval("bar("+n+")", 500);
Do this:
setInterval(function() { bar(n) }, 500);
Also, you need to accept questions to get any future answers, you do this by clicking the checkmark beside the answer that helped you resolve the issue. It gives you rep, the answerer rep, and helps the next googler find the appropriate answer faster.
Upvotes: 3