Skip to content

Instantly share code, notes, and snippets.

@cuth
Created April 17, 2015 19:30
Show Gist options
  • Save cuth/e0e73374799891a82a69 to your computer and use it in GitHub Desktop.
Save cuth/e0e73374799891a82a69 to your computer and use it in GitHub Desktop.
Run a function once
var once = function (fn) {
'use strict';
var ret;
var called = false;
return function () {
if (called) {
return ret;
}
called = true;
ret = fn.apply(this, arguments);
fn = null;
return ret;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment