Skip to content

Instantly share code, notes, and snippets.

@egobrain
Last active December 20, 2015 05:38
Show Gist options
  • Save egobrain/6079386 to your computer and use it in GitHub Desktop.
Save egobrain/6079386 to your computer and use it in GitHub Desktop.
Call only last defined function wrapper (Js)
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