4 points · by uptownhr · 11y ago · 6 comments
I don't think this really exists in other languages outside of JS. Where you can send in a parameter this way. I understand that the test variable becomes what ever you pass in the tail end but how does this work? What is this called so I can better ask other JS developers?
http://benalman.com/news/2010/11/immediately-invoked-functio...
Not unique to js, e.g. upcoming php v7 will support these.
var func = (function(test){console.log(test)});
func(1);
What's going on is you're creating an anonymous function, and then calling it.(function() { var x = 1; console.log(x); })();
console.log(x);
Would output:
1
undefined