Last active
December 20, 2015 05:38
-
-
Save egobrain/6079386 to your computer and use it in GitHub Desktop.
Call only last defined function wrapper (Js)
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 CallOnceConstructor = function () { | |
var cache = {}; | |
return function (f) { | |
if (cache.f_link) {cache.f_link.f = null}; | |
var f_link = {f: f}; | |
cache.f_link = f_link | |
return function() { | |
if (f_link.f) f_link.f.apply(null, arguments); | |
}; | |
} | |
}; | |
// example | |
// var call_last = CallOnceConstructor() | |
// var f1 = call_last(...) | |
// var f2 = call_last(...) | |
// var f3 = call_last(...) | |
// only f3 will be performed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment