S
S
someserj2016-08-03 13:36:25
JavaScript
someserj, 2016-08-03 13:36:25

Why does an anonymous function need to be wrapped in parentheses?

why write like that?

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

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Risent Veber, 2016-08-03
@someserj

In the case of code concatenation from multiple files by assemblers, where this may lead to an error in the resulting code. Specifically, in this example, the function is meaningless. it cannot be called.

N
Nikita Shchypylov, 2016-08-03
@Nikulio

Because you wrote it wrong
Anonymous function calls itself
So right:

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question