Created
July 5, 2016 15:43
-
-
Save VivienAdnot/3a5da9eb2e0f09440536d00e5284c6c5 to your computer and use it in GitHub Desktop.
call the function once, the other times it won't be called
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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