Thursday, 22 August 2013

Assign and execute Javascript function simultaneously

Assign and execute Javascript function simultaneously

I think the answer to this question is that it is impossible, but I
thought it would be worth asking here anyway.
Is there a more elegant way of writing something like this, where
myFunction is asigned to the function func but func is also executed
during the assignment?
var myFunction = (function(){
var func = function(){
console.log('hello world');
};
func();
return func;
})();
...
myFunction();

No comments:

Post a Comment