Created
May 25, 2015 16:16
-
-
Save Janking/604b466d1a16537df2da to your computer and use it in GitHub Desktop.
函数节流
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//函数节流 | |
var throttle = function (fn,interval){ | |
var __self = fn, | |
timer, | |
firstTime = true; | |
var fun = function(){ | |
var args = arguments, | |
__me = this, | |
outerTime = firstTime; | |
console.log(arguments) | |
console.log(timer) | |
if(firstTime){ | |
__self.apply(__me,args); | |
return firstTime = false; | |
} | |
if(timer){ | |
return false; | |
} | |
timer = setTimeout(function(){ | |
clearTimeout(timer); | |
timer = null; | |
__self.apply(__me,args); | |
}, interval||500); | |
}; | |
console.log(fun) | |
return fun; | |
} | |
var ff = throttle(function(){ | |
console.log(1) | |
},2000); | |
window.onresize = ff; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment