// 디바운싱
const clickBtn = document.querySelector('#clickBtn');
const clickCnt = document.querySelector('#clickCnt');
const debouncingCnt = document.querySelector('#debouncingCnt');
let timerId;
function debouncing(func, timeout = 300) {
clearTimeout(timerId);
timerId = setTimeout(func, timeout);
}
function delayFunction() {
debouncingCnt.innerHTML = parseInt(debouncingCnt.innerHTML) + 1;
}
clickBtn.addEventListener('click', () => {
clickCnt.innerHTML = parseInt(clickCnt.innerHTML) + 1;
debouncing(delayFunction);
});
// 쓰로틀링
const clickBtn = document.querySelector('#clickBtn');
const clickCnt = document.querySelector('#clickCnt');
const throttlingCnt = document.querySelector('#throttlingCnt');
let timerId;
function throttling(func, timeout = 300) {
if (timerId) {
return;
}
timerId = setTimeout(() => {
func();
timerId = undefined;
}, timeout);
}
function delayFunction() {
throttlingCnt.innerHTML = parseInt(throttlingCnt.innerHTML) + 1;
}
clickBtn.addEventListener('click', () => {
clickCnt.innerHTML = parseInt(clickCnt.innerHTML) + 1;
throttling(delayFunction);
});
[Node.js] 심화 이론 (4) (SOLID: SRP / OCP / LSP / ISP / DIP) (0) | 2024.02.19 |
---|---|
[Node.js] 심화 이론 (1-3) (객체 지향 구분 기준: 캡슐화 / 다형성 / 상속 / 추상화) (0) | 2024.02.19 |
[Node.js] Windows 환경 Error: EPERM: operation not permitted 2 (0) | 2024.01.29 |
[Node.js] Windows 환경 Error: EPERM: operation not permitted (1) | 2024.01.29 |
[MySQL] Transaction과 ACID (2) | 2024.01.26 |