You should not assign a link to a function and call the function at the same time. This can cause the heads to explode, as this adds to the already existing possibilities of assigning a variable to a link, assigning a variable to a return, or assigning a variable to the result of the assignment. A way to make it possible for anyone else to read your code would be to do this in two lines. If you want to wrap this in a function, it would be something like this:
var doThing = (function() { var inner = function() {
This in itself buys you nothing but obfuscation, doing it in a simple way, since the call will not be held independently. However, you could create a function that does this:
var callAndRef = function(funk) { funk(); return funk; };
and then
var doThing = callAndRef(function() {
or if you felt even more amiable and worked with you JS guru, you can drop it on Function.prototype and associate it with the declaration. You can also perforate in call / apply to support the this link and arguments (but it looks like it will be just noise for your current question).
All this must be done with utmost care . Of course, you should not go this route to save yourself, to type a couple of additional lines on one command.
Matt Whipple Sep 10 '12 at 20:32 2012-09-10 20:32
source share