1

I can't seem to find a reference that describes the following syntax:

 func() ();

This invocation of func is at the end of a constructor. Other invocations within the constructor are 'normal'.

1
  • func returns a function when ran. So, you're running func(), then running the function it returns. Commented Oct 2, 2013 at 18:51

3 Answers 3

3

func() returns a function, which is then invoked by the second set of ().

function func () {
  return function () {
    alert("ok!");
  }
}

func()(); // ok!
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Taking a closer look at the 'func' code, I see that is what it's doing.
1
func()();

is equivalent to:

var tempfunc = func();
tempfunc();

This is used for running a function that returns another function.

Comments

0

To avoid any confusion: We know that functions get invoked like this:

functionName ();

So anything before the () is the function name,

In the case of func() () put in mind that the func() is replacing the functionName, so this is also a function call, but even func() itself is a function, so we conclude that this is a function withing a function.

And for a more appropriate definition: func() () is a function that has another function as its return value, and by doing this we are calling that returned function to be executed.

1 Comment

Right. I really need more sleep at night!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.