AIRBNB Javascript Code specification important points Summary Es6

Source: Internet
Author: User

Chinese original address

1. Use const rather than VAR for all references. This ensures that you cannot repeatedly assign values to references.

Let is used when a change reference is required.

Both const and let are block-scoped scopes.

2. How to create an object:

Const item = {};

Use shorthand for object properties, and group the attributes for shorthand.

3. How to create an array:

Const ARR = [];

Use Arr.push () to replace the direct assignment.

Use the extension operator to assign an array of values: Arrcopy = [... arr];

Use Array.from () to convert a class array object to a group:

const FOO = Document.queryselectorall ('. Foo ');

CONST nodes = Aarry.from (foo);

4. Deconstruction:

Use deconstructing to access and use multi-attribute objects:

function Getfullname ({firstName, lastName}) {  return  ' ${firstname} ${lastname} ';}

An array is also used to assign values:

Const ARR = [1, 2, 3, 4//  equals first = Arr[0],second = Arr[1]

Use object deconstruction when returning multiple values: This does not care about the order of the attributes

function Returninput (input) {    ...     return {left, right, top, bottom};        = ProcessInput (input);

5.Strings

Use template strings instead of string links when programmatically generating strings

function Sayhi (name) {    return ' How is You, ${name}?  `;}

6. Functions

Using function declarations instead of function expressions

function foo () {}

The function expression that is called immediately:

() = {    console.log (' Welcome to the Internet. Please follow me. ' );}) ();

Never declare a function in a non-function code block (if,while) and assign that function to a variable.

Let test; if (current) {    = () = () = {        ...    };}

Do not use arguments, you can choose rest syntax ... Alternative. Rest is a real array, and you can specify the parameters you want to pass in

function cont (...args) {    return args.join (');}

Specify default values directly to the parameters of the function, and do not use a variable function parameter

function fn (opts = {}) {...}

7. Constructors

Always use class to avoid direct manipulation of prototype.

Use extends inheritance.

Method can return this to help with chained calls.

Not finished

AIRBNB Javascript Code specification important points Summary Es6

Related Article

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.