JSFiddle - React, Tailwind, and code Playground

by stevenhollidge

JavaScript

function add(a, b) {
    return a+b;
}

function once(func) {
    return function () {
        var f = func;
        func = null;
        return f.apply(
            this,
            arguments
        );
    };
}

var add_once = once(add);
console.log(add_once(3, 4));  // 7
console.log(add_once(3, 4));  // throws as f is now null