I want to define a self executing anonymous function, but have it run several times with different parameters.
(function(x){ console.log(x*x)})(2)
// output: 4
// I know this syntax is wrong, I am
// demonstrating how I would imagine it being implemented
(function(x){ console.log(x*x)})(2)(5)
// output is error, desired output: 4{Newline}25
Is it possible?
Edit: Based on answer from @Charmander, it seems it is possible
and almost certainly a bad idea, but this works as I would expect…
(function(x){ console.log(x*x); return arguments.callee})(2)(5)
You can either store the anonymous function in a variable.
Or you could have the function return itself if you are really bent on making it an immediately-invoked function expression (iife).