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?

asked May 31, 2015 at 15:50

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.
answered May 31, 2015 at 15:57
Sign up to request clarification or add additional context in comments.

Comments

0

"functions in objects" are called methods.

var foo = {
 x: function() {} // method
} 
answered May 31, 2015 at 17:06

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.