That's easy to accomplish, as javascript functions are objects that can have members and properties:
var callMeOnlyOnce=function(){
if(this.alreadyCalled)return;
alert('calling for the first time');
this.alreadyCalled=true;
};
// alert box comes
callMeOnlyOnce();
// no alert box
callMeOnlyOnce();
EDIT:
As pointed out correctly by CMS, using this is not that easy. Here's a revised version that uses a custom namespace instead of this.
if(!window.mynamespace){
window.mynamespace={};
}
mynamespace.callMeOnlyOnce=function(){
if(mynamespace.alreadyCalled)return;
alert('calling for the first time');
mynamespace.alreadyCalled=true;
};
// alert box comes
mynamespace.callMeOnlyOnce();
// no alert box
mynamespace.callMeOnlyOnce();