Practical guides, tutorials, and insights from years of building web and desktop applications. Check out code examples you can actually use!
Repeated function calls using an abstract pattern in Javascript
Use this if you want to repeatedly call a function for known arguments, or in case you just need a IIFE. If you want a repeatedly called functions, you would typically - Call function in a loop Use recursion For e.g. - function printStr(str) { console.log(str); } printStr("hello"); printStr("people"); /* hello people */ You can do it in a more concise way like so - (function(str) { console.log(str); return arguments.callee; // return function for next call })("hello")("world")("and")("people"); /* hello world and people */ Note that you are not returning a string, but a whole function and calling that function for the given arguments. In the statement, we use arguments to call the function that returns a function, and invoke the returned function on a specific argument thereon. ...