diff --git a/source/Ox/js/Function.js b/source/Ox/js/Function.js index bbcdf9aa..ee6476e0 100644 --- a/source/Ox/js/Function.js +++ b/source/Ox/js/Function.js @@ -59,8 +59,8 @@ Ox.cache = function(fn, options) { }; /*@ -Ox.debounce Runs a function once it stops being called for a given time frame - (fn[, ms][, immediate]) -> Throttled function +Ox.debounce Runs a function once it stops being called for a given interval + (fn[, ms][, immediate]) -> Debounced function fn Function to debounce ms Interval in milliseconds immediate If true, function is called once immediately @@ -113,6 +113,21 @@ Ox.noop = function() { Ox.isFunction(callback) && callback(); }; +/*@ +Ox.once Runs a function once, and then never again + (fn[, ms]) -> Function that will run only once + fn Function to run once +@*/ +Ox.once = function(fn) { + var once = false; + return function() { + if (!once) { + once = true; + fn.apply(null, args); + } + }; +}; + /*@ Ox.queue Queue of asynchronous function calls with cached results The results are cached based on all arguments to `fn`, except the last one, @@ -179,7 +194,7 @@ Ox.queue = function(fn, maxThreads) { }; /*@ -Ox.throttle Runs a function at most once per given time frame +Ox.throttle Runs a function at most once per given interval (fn[, ms]) -> Throttled function fn Function to throttle ms Interval in milliseconds