Informal JS syntax

Source: Internet
Author: User
Tags hasownproperty

There is a format variant (the variant did not pass the JSLint test) over the curly braces and put the IF statement on the same line.

The benefit of this is that the loop statement becomes more readable (the x is manipulated directly for each element that owns the attribute x).

The result of this is that it takes less indentation to get the loop done:

// call hasOwnProperty () in Object.prototype to filter the prototype property, and avoid having access to other methods of object when enumerating the man's methods.  var  i,    = Object.prototype.hasOwnProperty;  for inch Mans) {    if (Hasown.call (man,i)) {// filter                   console.log (i," : " , Man[i]);}

            ⇓

// Warning: cannot be checked by JSLint var I,     = Object.prototype.hasOwnProperty;  for inch if (Hasown.call (Man,i)) {// filter                   console.log (i,":", Man[i]);}

The same if statement also has this kind of ellipsis, I see colleagues write Java write after writing JS also so write,

But there's a problem with writing in Java:

if ()
When you do not use curly braces, there is no declaration, because that involves scopes, and no curly brackets and no scopes.

See the simple question behind: a discussion of if without parentheses

In C, C + + and C # are correct, even in Vs2005 such Java code is correct, because this form of code in different compilation methods will have different interpretations (such as the scope of the form I is default to the IF () {} In the form of the same. Then the form will be correct). From this can be seen,1, when writing code, as far as possible with the specification,2

I think I'd rather not write like this!

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.