Skip to content

Instantly share code, notes, and snippets.

@VivienAdnot
Created July 5, 2016 15:43
Show Gist options
  • Save VivienAdnot/3a5da9eb2e0f09440536d00e5284c6c5 to your computer and use it in GitHub Desktop.
Save VivienAdnot/3a5da9eb2e0f09440536d00e5284c6c5 to your computer and use it in GitHub Desktop.
call the function once, the other times it won't be called
function once(fn) {
var returnValue, called = false;
return function () {
if (!called) {
called = true;
returnValue = fn.apply(this, arguments);
}
return returnValue;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment