JavaScript parentheses have five kinds of semantics
Semantic 1, Function declaration time parameter table
Copy Code code as follows:
function func (ARG1,ARG2) {
// ...
}
Semantic 2, used in conjunction with some statements to achieve certain limitations
Copy Code code as follows:
Use with for in
For (var a in obj) {
// ...
}
And if used together
if (boo) {
//...
}
Use with the while
while (Boo) {
// ...
}
Use with Do While
do{
// ...
}while (Boo)
Note: When used with an if, while, and do, the parentheses convert the result of the expression into a Boolean value implicitly. See implicit type conversions in JavaScript.
Semantics 3, used with new to pass values (arguments)
Copy Code code as follows:
Suppose the class person is already defined, it has two field names (name), age
var p1 = new Person (' Jack ', 26);
Semantic 4, as the invocation operator of a function or object method (if a parameter is defined, it can also be passed as Semantic 3)
Copy Code code as follows:
Suppose you've defined a function func
Func ();
Suppose object obj has been defined and has the Func method
Obj.func ();
Here to mention the typeof operator, some people like to use this
typeof (XXX);
Note that the typeof parenthesis is not semantic 4 (that is, not a function call), but rather the semantic 5 that follows. I use typeof generally without the following parentheses.
Semantic 5, forcing expression operations
The most familiar thing about semantic 5 is using Eval to parse JSON
Copy Code code as follows:
function Strtojson (str) {
Mandatory operator () on both sides of the string in eval
var json = eval (' (' + str + ') ');
return JSON;
}
And if you use more of the anonymous function self execution
Copy Code code as follows:
(function () {
// ...
})();