This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<link rel="stylesheet" href="./styles.css"> | |
</head> | |
<body> | |
<h1>hello</h1> | |
<img src="./imgs/cat.jpeg" alt=""> |
This file contains hidden or 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
function debounce(originalFn, timeoutMs) { | |
let timeout; | |
return (...args) => { | |
clearTimeout(timeout); // clear timeout every time the function is called | |
timeout = setTimeout(() => originalFn(...args), timeoutMs); // call the original function once "timeoutMs" ms after the last call have elapsed | |
}; | |
} |
This file contains hidden or 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
// Creates a throttled function that only invokes "originalFn" at most once per every "delayMs" milliseconds | |
function throttle(originalFn, delayMs) { | |
let timeout; // timeout to keep track of the executions | |
return (...args) => { | |
if (timeout) { // if timeout is set, this is NOT the first execution, so ignore | |
return; | |
} | |
// this is the first execution which we need to delay by "delayMs" milliseconds | |
timeout = setTimeout(() => { |