Home  >  Article  >  WeChat Applet  >  ES6 new features development WeChat applet (1)

ES6 new features development WeChat applet (1)

迷茫
迷茫Original
2017-03-25 17:22:521855browse

ECMAScript 6 (ES6 for short) is the latest standard for the JavaScript language. Because the current version of ES6 was released in 2015, it is also called ECMAScript 2015.

WeChat applet supports most of the new features of ES6.

Constants(constants)

ES6 has added the const keyword, which is used to declare constants. Once declared, the value of the constant cannot be changed. .

ES6 new features development WeChat applet (1)

const is only valid within the block-level scope where it is declared.

Scoping(scope)

ES6 has added the let keyword, which is used to declare variables, but the declaration only affects the code block Valid within.

ES6 new features development WeChat applet (1)

The above code is in the code block and declares two variables using let and var respectively. Then these two variables are called outside the code block. As a result, the variable declared by let reports an error, and the variable declared by var returns the correct value. This shows that the variable declared by let is only valid in the code block in which it is located.

ES6 new features development WeChat applet (1)

The counter i in the above code is only valid within the for loop body.

let adds a new block-level scope to JavaScript.

ES6 new features development WeChat applet (1)

#The above function has two code blocks, both of which declare variables x and y, and output after running 1 2. This means that the outer code block is not affected by the inner code block. If you use var to define variable n, the final output value is 10 20.

Arrow Functions

The arrow function is a very good feature provided by ES6 in terms of syntax. Its characteristics are:

The syntax is more concise.

Grammatically fixed this object.

One parameter

ES6 new features development WeChat applet (1)

##Multiple parameters

ES6 new features development WeChat applet (1)ES6 new features development WeChat applet (1)




#Array traversal

ES6 new features development WeChat applet (1)ES6 new features development WeChat applet (1)
##Extended Parameter Handling (parameter expansion)

Allows setting default values ​​for function parameters, which is written directly after the parameter definition.

ES6 new features development WeChat applet (1)

Rest variable parameters (represented by "....") are named parameters used in functions Also accepts an indefinite number of unnamed parameters.

ES6 new features development WeChat applet (1)

The Spread operator is the same as the Rest variable parameter, and both use "..." to represent the Spread operation The operator allows us to pass the parameters in the array into the function one by one.

ES6 new features development WeChat applet (1)

The above is the detailed content of ES6 new features development WeChat applet (1). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn