That ends with parentheses () and a semicolon;

in the object creation method , for example , this code:

var tiny.show=function(){ }(); 

that parentheses () and semicolons end;

+4
source share
3 answers

The function is called in the bracket, and the return value of the function is assigned to tiny.show (which does not make sense to use var there).

+5
source

; - optional end of the operator token in Javascript. If you skip it, the interpreter treats the end of the line as the end of the statement marker. However, the use of operators ; for distinction it is considered improved for readability by many.

The initial () means that you are going to define an anonymous function and assign it tiny.show . End () labels and call, i.e. Function call.

+3
source

This is a common JavaScript programming idiom used to implement a module template, as well as a factory object template. You might think of it as a way to create some kind of private area in JavaScript

Here are some good readings on the topic:

+1
source

Source: https://habr.com/ru/post/1413202/


All Articles