Skip to content

Instantly share code, notes, and snippets.

@wenzhixin
Created June 20, 2013 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wenzhixin/5820136 to your computer and use it in GitHub Desktop.
Save wenzhixin/5820136 to your computer and use it in GitHub Desktop.
定时器
function timer(func, start, interval, end) {
start = start || 0;
if (arguments.length <= 2) {
setTimeout(func, start);
} else {
var repeat = function() {
var i = setInterval(func, interval);
end && setTimeout(function() {
clearInterval(i);
}, end);
};
setTimeout(repeat, start);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment