Skip to content

Instantly share code, notes, and snippets.

@ianpgall
Last active December 20, 2015 00:19
Show Gist options
  • Save ianpgall/6040542 to your computer and use it in GitHub Desktop.
Save ianpgall/6040542 to your computer and use it in GitHub Desktop.
JavaScript function that allows the execution of a Function once
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