Created
April 17, 2015 19:30
-
-
Save cuth/e0e73374799891a82a69 to your computer and use it in GitHub Desktop.
Run a function once
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
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