JSFiddle - React, Tailwind, and code Playground

by joplomacedo

JavaScript

function addCache( f ) {
	const toReturn = () => toReturn.cache = f();
  toReturn.cache = undefined;
  
	return toReturn;
}

let i = 0;
func = addCache(function () {
	return ++i;
});




console.log(func.cache);
func();
console.log(func.cache);