Skip to content

Instantly share code, notes, and snippets.

@gracefullight
Created December 22, 2016 11:21
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 gracefullight/67b7b55641fac76d64dc7c0f3b936a8e to your computer and use it in GitHub Desktop.
Save gracefullight/67b7b55641fac76d64dc7c0f3b936a8e to your computer and use it in GitHub Desktop.
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