Last active
December 20, 2015 00:19
-
-
Save ianpgall/6040542 to your computer and use it in GitHub Desktop.
JavaScript function that allows the execution of a Function once
This file contains hidden or 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
var Once = (function () { | |
"use strict"; | |
var A, F, func; | |
A = []; | |
F = function () { return undefined; }; | |
func = function (f) { | |
var ret, ran, retValue; | |
ran = false; | |
ret = function () { | |
if (ran) { | |
return retValue; | |
} | |
ran = true; | |
retValue = F.apply.call(f, this, A.slice.call(arguments, 0)); | |
return retValue; | |
}; | |
return ret; | |
}; | |
return func; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment