Reza Abdi
Reza Abdi

Reputation: 41

what do end parenthesis() and semicolon ;

in the create object method like this Code:

var tiny.show=function(){  

}();

what do end parenthesis() and semicolon ;

Upvotes: 4

Views: 114

Answers (3)

Joseph Moniz
Joseph Moniz

Reputation: 435

This is a common programming idiom in JavaScript used to implement to module pattern as well as the object factory pattern. You can kind of think of it as a way to create a sort of private scope in JavaScript

Here are some good reads on the topic:

Upvotes: 1

dirkgently
dirkgently

Reputation: 111130

The ; is an optional end of statement marker in Javascript. If you skip it, the interpreter considers the end of line as the end of statement marker. However, using a ; to delimit statements is considered to improve readability by many.

The initial () denotes that you are about to define an anonymous function and assign it to tiny.show. The final () marks and invocation i.e. function call.

Upvotes: 3

alex
alex

Reputation: 490233

The parenthesis invoke the function and that function's returned value is assigned to tiny.show (which doesn't make sense to use a var there).

Upvotes: 5

Related Questions