【发布时间】:2017-03-18 19:44:14
【问题描述】:
有人可以向我解释为什么每次调用函数时 lastEventTimestamp 都不会重置为 null 吗?
Function.prototype.throttle = function (milliseconds, context) {
var baseFunction = this,
lastEventTimestamp = null,
limit = milliseconds;
return function () {
var self = context || this,
args = arguments,
now = Date.now();
if (!lastEventTimestamp || now - lastEventTimestamp >= limit) {
lastEventTimestamp = now;
baseFunction.apply(self, args);
}
};
};
【问题讨论】:
-
调用了一个函数:哪个函数?请显示产生您意想不到的结果的代码?
标签: javascript throttling