Reputation: 552
Is there an easier way to check if a javascript function has already been called and is active besides what I have below, or is what I have below already optimized...
var isDefined = function(func) {
if(func !== undefined)
{
return true;
}
else
{
return false;
}
}
Upvotes: 0
Views: 53
Reputation: 8610
JavaScript does nothing to retain memory of a function having already been called. You can put a Boolean var flag outside of it, set it to true inside, and ensure its scope doesn't leak by putting it inside an IIFE, which may give you what you want.
If what you're doing is related to click/event listening, you may want to use something like JQuery's $.once()
, which adds an event listener that removes itself after occurring once.
Upvotes: 2
Reputation: 6410
var isDefined = function(func) {
return (func !== undefined);
}
Upvotes: -1