can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
43 lines (42 loc) • 1.14 kB
JavaScript
/*!
* CanJS - 2.3.34
* http://canjs.com/
* Copyright (c) 2018 Bitovi
* Mon, 30 Apr 2018 20:56:51 GMT
* Licensed MIT
*/
/*can@2.3.34#util/function/function*/
define(['can/util/library'], function (can) {
can.debounce = function (fn, time, context) {
var timeout;
return function () {
var args = arguments;
clearTimeout(timeout);
timeout = setTimeout(can.proxy(function () {
fn.apply(this, args);
}, context || this), time);
};
};
can.throttle = function (fn, time, context) {
var run;
return function () {
var args = arguments;
var ctx = context || this;
if (!run) {
run = true;
setTimeout(function () {
fn.apply(ctx, args);
run = false;
}, time);
}
};
};
can.defer = function (fn, context) {
var args = arguments;
var ctx = context || this;
setTimeout(function () {
fn.apply(ctx, args);
}, 0);
};
return can;
});