Skip to content

Instantly share code, notes, and snippets.

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

Mikael djsd123

🏠
Working from home
  • London
View GitHub Profile
@djsd123
djsd123 / index.ts
Created July 18, 2022 14:08
A Function in Typescript/Javascript that can only be called/executed once
/*
I wanted a function that would only work once where all subsequent calls would result in a noop
I stumbled upon this Stackoverflow question: https://stackoverflow.com/questions/12713564/function-in-javascript-that-can-be-called-only-once
However, I found some of the answers difficult to implement in Typescript but on the bright side. I learnt a little about closures.
I added my simple workaround here: https://stackoverflow.com/a/72992927/2719085 and below.
*/
let printName = (name: string) => {
console.log(name)

Keybase proof

I hereby claim:

To claim this, I am signing this object: