Skip to main content
Copy edited (e.g. ref. <http://en.wikipedia.org/wiki/User:Tony1/How_to_improve_your_writing#Misplaced_formality>). Removed meta information (this can be put in comments). Dressed the naked link.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

this maybe a little late however myMy understanding of the asker's question is such that:

howHow does this magic work:

(function(){}) ('input') // utilisedUsed in his example 

I maybemay be wrong however. However, the usual practice that people are familiar with is:

(function(){}('input') )  

theThe reason is such that javascriptJavaScript parentheses akaAKA ()(), can't contain statements and when the parser encounters encounters the function keyword, it knows to parse it as a function expression and not a function declaration.

sourceSource: blog post http://benalman.com/news/2010/11/immediately-invoked-function-expression/Immediately-Invoked Function Expression (IIFE)

this maybe a little late however my understanding of the asker's question is such that

how does this magic work:

(function(){}) ('input') // utilised in his example 

I maybe wrong however the usual practice that people are familiar with is

(function(){}('input') )  

the reason is such that javascript parentheses aka (), can't contain statements and when the parser encounters the function keyword, it knows to parse it as a function expression and not a function declaration.

source: http://benalman.com/news/2010/11/immediately-invoked-function-expression/

My understanding of the asker's question is such that:

How does this magic work:

(function(){}) ('input') // Used in his example 

I may be wrong. However, the usual practice that people are familiar with is:

(function(){}('input') ) 

The reason is such that JavaScript parentheses AKA (), can't contain statements and when the parser encounters the function keyword, it knows to parse it as a function expression and not a function declaration.

Source: blog post Immediately-Invoked Function Expression (IIFE)

added 16 characters in body
Source Link
laycat
  • 5.7k
  • 8
  • 36
  • 47

this maybe a little late however my understanding of the asker's question is such that

how does this magic work:

(function(){}) ('input') // utilised in his example

(function(){}) ('input') // utilised in his example 

I maybe wrong however the usual practice that people are familiar with is

(function(){}('input') )

(function(){}('input') ) 

the reason is such that javascript parentheses aka (), can't contain statements and when the parser encounters the function keyword, it knows to parse it as a function expression and not a function declaration.

source: http://benalman.com/news/2010/11/immediately-invoked-function-expression/

this maybe a little late however my understanding of the asker's question is such that

how does this magic work:

(function(){}) ('input') // utilised in his example

I maybe wrong however the usual practice that people are familiar with is

(function(){}('input') )

the reason is such that javascript parentheses can't contain statements and when the parser encounters the function keyword, it knows to parse it as a function expression and not a function declaration.

source: http://benalman.com/news/2010/11/immediately-invoked-function-expression/

this maybe a little late however my understanding of the asker's question is such that

how does this magic work:

(function(){}) ('input') // utilised in his example 

I maybe wrong however the usual practice that people are familiar with is

(function(){}('input') ) 

the reason is such that javascript parentheses aka (), can't contain statements and when the parser encounters the function keyword, it knows to parse it as a function expression and not a function declaration.

source: http://benalman.com/news/2010/11/immediately-invoked-function-expression/

Source Link
laycat
  • 5.7k
  • 8
  • 36
  • 47

this maybe a little late however my understanding of the asker's question is such that

how does this magic work:

(function(){}) ('input') // utilised in his example

I maybe wrong however the usual practice that people are familiar with is

(function(){}('input') )

the reason is such that javascript parentheses can't contain statements and when the parser encounters the function keyword, it knows to parse it as a function expression and not a function declaration.

source: http://benalman.com/news/2010/11/immediately-invoked-function-expression/