Skip to content

Instantly share code, notes, and snippets.

View joelbarbosa's full-sized avatar
🏠
Working from home

Joel Barbosa joelbarbosa

🏠
Working from home
View GitHub Profile
const makeInterable = (array) => {
let nextIndex = 0;
return {
next: () => {
if (nextIndex < array.length) {
return {value: array[nextIndex ++], done: false}
} else {
return {done: true};
}
const button = document.querySelector('button');
button.addEventListener("click", () => resizeWithTroattle(10));
const resizeWithTroattle = throttle(executeResize, 3000);
window.addEventListener("resize", () => resizeWithTroattle('test'));
function executeResize(number) {
console.log("resize: " + number);
}
function throttle(fn, time) {
@joelbarbosa
joelbarbosa / eventtarget.ts
Last active April 22, 2021 19:02
type EventTarget with typescript
type EventTarget<T> = EventTarget & T;
interface FormEvent<T> extends Event {
target: EventTarget<T>;
}
function handleSubmit(event: FormEvent<{price: number}>) {
event.target.price;
}