-
Notifications
You must be signed in to change notification settings - Fork 0
/
functionTimeLimiter.js
45 lines (37 loc) · 1.04 KB
/
functionTimeLimiter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//var limitExecByInterval = function(fn, time) {
// var lock, execOnUnlock, args;
// return function() {
// args = arguments;
// if (!lock) {
// lock = true;
// var scope = this;
// setTimeout(function(){
// lock = false;
// if (execOnUnlock) {
// args.callee.apply(scope, args);
// execOnUnlock = false;
// }
// }, time);
// return fn.apply(this, args);
// } else execOnUnlock = true;
// }
//}
Function.prototype.functionLimitByTime = function(time){
var arg = [],lock = false,fn = this;
return function(){
arg = arguments;
if(!lock){
lock = true;
setTimeout(function(){
lock = false;
},time);
return fn.apply(this,arg);
}
}
}
function nikita(){
console.log("Hello!!!");
var x = 2;
return x;
}
nikita = nikita.functionLimitByTime(100);