Created
October 8, 2020 05:23
-
-
Save leegeunhyeok/e232887a4b8e549ac25386377c7ca104 to your computer and use it in GitHub Desktop.
Eval only once
This file contains 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
let init = false; | |
const doSomething = () => { | |
if (!init && (init = true)) { | |
console.log('Only once'); | |
return; | |
} | |
console.log('Do something'); | |
} | |
doSomething(); // Only once | |
doSomething(); // Do something | |
doSomething(); // Do something | |
doSomething(); // Do something |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment