The ambiguity of the JavaScript parenthesis "()"

Source: Internet
Author: User
Tags eval json

  This article mainly introduces the ambiguity of JavaScript parenthesis "()". Need friends can come to the reference, I hope to help you.

JavaScript parentheses have five semantics   semantics 1, function declaration when parameter table     code as follows: Functions func (ARG1,ARG2) {   //... }  & nbsp Semantic 2, which is used in conjunction with some statements to achieve certain limitations   code as follows://for use with   for (Var a in obj) {   //... }   //And if Working with   if (boo) {   //... }   //And while using   while (boo) {   //... }&NB Sp  //And doing while working with   do{   //... }while (Boo)     NOTE: When used with an if, while and do, the parentheses will include the table The result is implicitly converted to a Boolean value. See implicit type conversions in JavaScript.   Semantics 3, used with new to pass the value (argument)     code as follows://Suppose you have defined a class person, it has two field names, age (aged)   var p1 = new Person (' Jack ' ;    Semantics 4, as the invocation operator of a function or object method (if the parameter is defined and can be passed as semantics 3) copy the code as follows://Assuming that the function is defined func  func ();   // Suppose the object obj has been defined and has the Func method   Obj.func ();    Here The typeof operator, some people like to use   typeof (XXX);   Note that the TypeOf parenthesis is not semantic 4 (that is, not a function call), but rather the semantic 5 that is mentioned later. I use typeof generally without the following parentheses.     Semantics 5, enforcing expression operations     about Semantic 5, you're most familiar with using eval to parse JSOn     code is as follows: function Strtojson (str) {       //eval strings are both flanked by a mandatory operator ()       &NBS P;var json = eval (' (' + str + ') ');        return json; }    And if you use more anonymous functions copy code code as follows: (function () {   //... &n Bsp }) (); 
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.