Skip to content

Instantly share code, notes, and snippets.

@yy-dev7
Created March 21, 2017 01:35
Show Gist options
  • Save yy-dev7/dd837c80d7cf321be36cd246f05858d1 to your computer and use it in GitHub Desktop.
Save yy-dev7/dd837c80d7cf321be36cd246f05858d1 to your computer and use it in GitHub Desktop.
proxySynchronousFile
var synchronousFile = function(id) {
console.log('开始同步文件,id 为: ' + id);
}
// 虚拟代理http请求
var proxySynchronousFile = (function() {
var cache = [], timer
return function(id) {
cache.push(id)
if (timer) {
return
}
timer = setTimeout(function() {
synchronousFile(cache.join(','))
clearTimeout(timer)
timer = null
cache.length = 0
}, 3000)
}
}())
var checkbox = document.getElementsByTagName('input')
for (var i = 0, c; c = checkbox[i++];) {
c.onclick = function() {
if (this.checked) {
proxySynchronousFile(this.id)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment