views:

72

answers:

3

Is there any particular reason that this sort of construct would not work in JS? (JSLint does not accept it.)

(function(function(){

    }){

})()

I can see this type of chaining going on forever, or at least as far as one would want/need.

Does anyone have any thoughts?

A: 

Well... yeah, it wouldn't work because it's not meaningful to embed an anonymous function in the argument list of an anonymous function. What are you trying to specify, there?

chaos
A: 

You can create an anonymous function which accepts a function as an argument, and immediately pass it another anonymous function:

(function(fn) { })(function() { })

But I can't think of a single useful reason for doing that.

Gareth
+3  A: 

Did you mean:

(function () {
// ...
})((function () {
// ...
})());
Ates Goral