Skip to content

Instantly share code, notes, and snippets.

@srijanshetty
Created June 30, 2014 16:58
Show Gist options
  • Save srijanshetty/1e76c566a80b004dfbb1 to your computer and use it in GitHub Desktop.
Save srijanshetty/1e76c566a80b004dfbb1 to your computer and use it in GitHub Desktop.
Only once function
var once = function(fn, context) {
return function() {
if(!fn) {
return undefined;
}
// We call the function only once
fn.apply(context || this, arguments);
// Set the function to null
fn = null;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment