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
mirageglobe
3,2422 gold badges35 silver badges32 bronze badges
2 Answers 2
There are a lot of concepts you've got wrong.
- Though functions are objects too, this isn't a object declaration, it's a normal function declaration.
- The functional form you've used is self-invoking function.
- 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
Amit Joki
59.4k7 gold badges80 silver badges97 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
"functions in objects" are called methods.
var foo = {
x: function() {} // method
}
answered May 31, 2015 at 17:06
brroshan
1,65017 silver badges19 bronze badges
Comments
lang-js