¿Cómo implementar el código después de la función? Debería invocar la función solo después de la tercera vez.
function after(count, funct) { // code... } var called = function () { console.log("hello"); }; var afterCalled = after(3, called); afterCalled(); // --> nothing is printed afterCalled(); // --> nothing is printed afterCalled(); // --> "hello" is printedPuede devolver una función que disminuya el contador y, si es cero, llama a la función entregada.
function after(count, funct) { return function () { if (!--count) funct(); }; } var called = function () { console.log("hello"); }; var afterCalled = after(3, called); afterCalled(); // --> nothing is printed console.log('.') afterCalled(); // --> nothing is printed console.log('.') afterCalled(); // --> "hello" is printed console.log('.') afterCalled(); // --> nothing is printed