What is ES6?
- ECMAScript 6 (hereinafter referred to as ES6) is the next generation standard JavaScript language, has been officially released in June 2015. Mozilla Corporation will be based on this standard, the introduction of JavaScript 2.0.
- ECMAScript is the international standard JavaScript language, JavaScript is the realization of ECMAScript.
- ES6 goal is to make the JavaScript language can be used to write large, complex applications, enterprise-class development language.
ES6 official Chinese network ( http://es6.ruanyifeng.com/ )
Variable definition (var, let, const)
- General functions are used to define the variable var, because it is a keyword may be pre-parsed.
- ES6 recommended to use let to define the variables, let's define general variables.
- const is a constant defined, can not be modified.
< Script type = "text / JavaScript" > <-! Define var value -> var HT = 20 is ; <-! Define let value -> let NN = 30 ; <-! Defined value const -> PCL const = 183 is ; Alert (HT); // 20 is Alert (NN); // 30 Alert (PCL); // 183 is HT = 21 is ; NN = 31 is ; // PCL= 184 ; // error, const are constants defined unmodifiable Alert (HT); // 21 is Alert (NN); // 31 is Alert (PCL); // 183 is </ Script >
Arrow function,
// function defined by the wording of the arrow
var FNRS = (A, B) => {
var RS = A + B;
Alert (RS);
}
// FNRS (1,2);
// a parameter can be omitted parentheses
var = a = fnRs2> {
Alert (a);
}
fnRs2 ( 'a lamp in the present not go off');
// arrow action function, this object can be bound (but where this is not the object window)
var = {Person
name: 'Tom',
Age: 18 is,
showname: function () {
the setTimeout (() => {
Alert (this.name);
}, 1000)
}
}
person.showName ();
class
ES6 also proposed the use of a class, class usage in es5 can be achieved, but since the new rules would be more clarity friends
Poetry {class constructor () { console.log ( 'mountain of wood Xi wood'); } } class the extends the Person Poetry { constructor () { Super (); console.log ( 'This is a blue lamp does not go off' ); } } the let new new HT = the Person ();
effect:
Deconstruction
someArray HT1 = var [0];
var someArray HT2 = [. 1];
var HT3 someArray = [2];
// destructuring assignment
the let [HT1, HT2, HT3] = someArray;
// The following example also
let [,, ht3 ] = [l, 2,3];
the console.log (HT3); //. 3
the let [HT1, ... Last] = [l, 2,3];
the console.log (Last); // [2, 3]
// Object deconstruct
the let {name, Age} = {name: "HT", Age: ". 17"};
the console.log (name); // HT
the console.log (Age); //. 17
// NOTE
{} = {EPT1 the let};
the console.log (EPT1); // undefined
the let EPT2} {} = {undefined;
the console.log (EPT2); // undefined
the let EPT3 {} = {null};
the console.log ( ept3); // null
Rest+ Spread
Comments ( https://segmentfault.com/a/1190000009992594 )
import and export
- By adding to the braces sex, echo and export output variable, the magnitude of the strain can be exposed to will sex, echo variable identifier in the form of files to be read into other
- Can not be written in such a way export sex, if this is equivalent to export "boy", the external file will get less than the value of the internal variables of the file sex because there is no external output variable interfaces, but the string output.
< Script type = "text / JavaScript" > // abbreviated form below var Sex = " Boy " ; var echo = function (value) { the console.log (value) } Export {Sex, echo} </ Script >
- A.js the import file acquiring internal variable, the variable in brackets {} from the variable a.js export file identifier.
import {sex,echo} from "a.js"
console.log(sex) // boy
echo(sex) // boy
Thanks for watching!