Underscore.js _.after() Function (original) (raw)

Last Updated : 25 Nov, 2021

Underscore.js is a JavaScript library that provides a lot of useful functions that help in the programming in a big way like the map, filter, invoke, etc even without using any built-in objects.

The _.after() function is an inbuilt function in Underscore.js library of JavaScript which is used to create a wrapper of function which doesn’t do anything in the beginning but from the stated count it starts calling the stated function. Moreover, it is useful in a grouping of asynchronous responses, as you need to be sure if all the async calls have ended or not before preceding.

Syntax:

_.after(count, function)

Parameters: It accepts two parameters which are specified below:

Return values: This method returns the count of the function called.

Example 1:

Output:

Show function will run for 5 times: GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks

Example 2:

<!DOCTYPE html>

<html>

<head>

`` <script src=

`` </script>

</head>

<body>

`` <button id= "button" >button</button>

`` <script>

`` show = () => {

`` console.log( "GeeksforGeeks" )

`` }

`` func = _.after(3, show);

`` let button = document.querySelector( "#button" );

`` let Run = () => {

console.log(Show `` function runs for `` 8 times:) ``

`` for (let i = 0; i < 10; i++) {

`` func();

`` }

`` }

`` button.addEventListener( "click" , Run)

`` </script>

</body>

</html>

Output:

button

Show function runs for 7 times: GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks GeeksforGeeks

Here, you need to click on the button in order to see the output.

Reference: https://underscorejs.org/#after

Similar Reads

Underscore.js Collections Functions
















Underscore.js Arrays Functions
















Underscore.js Functions















Underscore.js Object Functions
















Underscore.js Utility Functions















Underscore.js Questions