Possible Duplicate:
Can a JavaScript function return itself?
Consider the following javascript function:
var x = function(msg) {
alert(msg);
return x;
};
x('Hello')('World!');
This wil alert 'Hello' and 'World!'. Now I would like to rewrite the function without using a var x
into something like:
(function(msg)
{
alert(msg);
return this;
})('Hello')('World');
But this doesn't work. What am I doing wrong? How can I return my own function from the function?