Created
December 22, 2016 11:21
-
-
Save gracefullight/67b7b55641fac76d64dc7c0f3b936a8e 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 throttleFunction = (function() { | |
'use strict'; | |
var timeWindow = 500; // 여기에 시간(ms)을 지정한다 | |
var lastExecution = new Date((new Date()).getTime() - timeWindow); | |
// ES6 이하일 경우 ...args에 호출할 parameter 만큼 준다 function(arg1, arg2...) | |
var throttleFunction = function(...args) { | |
// 여기에 로직을 구현한다 | |
}; | |
return function() { | |
if ((lastExecution.getTime() + timeWindow) <= (new Date()).getTime()) { | |
lastExecution = new Date(); | |
return throttleFunction.apply(this, arguments); | |
} | |
}; | |
}()); | |
// 사용법 | |
throttleFunction(param1, param2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment