Skip to content Skip to sidebar Skip to footer

Re-invoking Iife

Why is that code block throws an error 'Uncaught ReferenceError: setSize is not defined' const canvas = document.querySelector('#draw'); (function setSize() { canvas.width = w

Solution 1:

Just define your setSize function and call it once (it should have the same effect as your IFFE).

const canvas = document.querySelector("#draw");

function setSize() {
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
}

setSize();

window.addEventListener("resize", () => {
    setSize();
})

Post a Comment for "Re-invoking Iife"