0

I came across the following recently, which seems to be an object declaration, starting with just a semi-colon. It works fine.

;(function() { var ..... = this; })()

Are there any difference in declaring it this way or if there are alternatives?

2 Answers 2

2

There are a lot of concepts you've got wrong.

  1. Though functions are objects too, this isn't a object declaration, it's a normal function declaration.
  2. The functional form you've used is self-invoking function.
  3. The semi-colon ; is used so that the code doesn't break when several scripts are minified into a single file.
Sign up to request clarification or add additional context in comments.

Comments

0

"functions in objects" are called methods.

var foo = {
     x: function() {} // method
} 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.