Показать сообщение отдельно
  #6 (permalink)  
Старый 02.07.2016, 22:17
Аватар для Vlasenko Fedor
Профессор
Отправить личное сообщение для Vlasenko Fedor Посмотреть профиль Найти все сообщения от Vlasenko Fedor
 
Регистрация: 13.03.2013
Сообщений: 1,572

Вариант
Function.prototype.limitExecByInterval = function (interval) {
    var fn = this, expireTime = 0, timer;
    return function () {
        var elapseTime = expireTime - new Date();
        if (elapseTime <= 0) {
            timer = clearTimeout(timer);
            fn.apply(this, arguments);
            expireTime = Number(new Date()) + interval;
        } else if (!timer) {
            var args = arguments, scope = this;
            timer = setTimeout(function () {
                expireTime = 0;
                args.callee.apply(scope, args);
            }, elapseTime);
        }
    }
};
var myFunc = function() {};
var myLimitedFunc = myFunc.limitExecByInterval(150);
Ответить с цитированием