UNPKG

can

Version:

MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.

42 lines (41 loc) 1 kB
/*! * 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*/ var can = require('../util.js'); 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); }; module.exports = can;