代码改变世界

js关卡函数,throat函数实现,定时运行函数

2018-06-30 12:17  muamaker  阅读(419)  评论(0编辑  收藏  举报
		function throat(callback,num){
			var timer = null;
			callback = callback || function(){};
			return function(){
				if(!timer){
					var that = this;
					var arg = arguments;
					timer = setTimeout(function(){
						callback.apply(that,arg);
						timer = null;
					},num);	
				}

			}
		}
		
		var throats = throat(function(e){
			console.log(e.screenX,e.screenY);
		},1000);
		
		window.onmousemove = function(e){
			throats(e);
		};