N
N
nadom2015-10-12 23:23:17
JavaScript
nadom, 2015-10-12 23:23:17

Why parentheses around nested JS functions?

Let's say there is a function, it has two nested ones:

function test() { 
  (function first($)
    { ...
                })		
  ((function second(r) {
    ...
                function in_second() { 
      }
    return $; 
    })
  }

Why are nested functions enclosed in round brackets?
(If some method is called later, it is clear why. And if it is not called?)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iCat, 2015-10-13
@iCat

I agree with Alexey Ten. You seem to have removed the extra parentheses.
Based on what's left and your question, I suspect you're interested in constructs like

(function(){
  // some code here
})();

This is the so-called. immediately invoked functions . Code within such a function will be immediately executed within its own variable scope.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question