For ES6 (template string, three operators, Symbol, iterator interface)

Template string

Action: easier to reconstruct the string

  • Template string must contain ``

  • Changing portion comprising using $ {xxx}

Shorthand object

  • Property of the same name can be omitted

  • Function can be omitted Function

Arrow function

Features arrow function

  • Arrow function does not own this, when this is not the function of the arrow called the decision, but when defined in this object is its

  • Extended understand:

    • this function of the arrow to see if there is a function of the outer layer

    • If there is, the outer layer of this function is a function of this internal arrow

    • If not, then this is the window

Where the shape parameter

  1. When there is no parameter

        let fun1 = () => console.log(a);
    fun1();
  2. Only one parameter of time

        let fun2 = a => console.log(a);
    fun2('aaa');

  3. two or more of the parameter when two () can not be omitted

          let fun3 = (x,y) => console.log(a);
  fun3(35,52);

Function body case

  1. When only one body of the function or the expression {statement} may be omitted ------> Results but will automatically executed statement or expression

  2. Function body case more than one statement or expression can not be omitted {}

Three operators

1.rest (variable) parameters

  To replace arguments, but flexible than arguments, only part of the last parameter Parameter

2. Extended operator

Object promise

1. Understanding

  • promise Object: represents a time in the future will happen (usually an asynchronous operation)

  • With the promise objects, asynchronous operation may be expressed in a synchronized process, avoiding deeply nested callback function (commonly known as callback function)

  • Promise ES6 is a constructor to generate promise Examples

2. The basic steps promise object

# Create Object promise 
the let promise = new new Promise (( resolove, Reject) => { // Initialization state Pending // perform asynchronous operation if ( asynchronous operation success) { Resolve ( value); // modify the status promise is fullfilled } {the else Reject ( errMsg An); // status is modified promise Rejected } }) # promise of the then call () promise. the then ( function ( Result => Console. log ( Result), erroring => Alert ( erroring) )










   
   

Three states 3.promsie object

  • pending: initialization state

  • fullfilled: success status

  • rejected: the failed state

4. Applications

  • Use premise ultra-try

  • The encapsulation process using the promise ajax request

    let requset = new XMLHttpRequset();
    requset.onreadystatechange = function(){
    }
    request.responseType = 'json';
    requset.open('GET',url);
    requset.send();

Symbol

ES6 new primitive data types

Features:

  1. Symbol value of the property value is only to resolve naming conflicts

  2. Symbol value can not be calculated with other data, including strings with strings spell

  3. 3.for in, for of traversal attribute not traverse symbol

use:

  1. Call the Symbol function to get the symbol value

  2. Pass parameters to identify

  3. Built-in Symbol value

    • In addition to defining Symbol values ​​other than their own use, ES6 also provides 11 built-in Symbol value, directed to a method of using internal language

      Symbol.iterator

    • Symbol.iterator properties of the object point to the default method is to traverse the object

iterator Interface

  The iterator interfaces deployed on the specified data type, can be used for of loop iterates

  Arrays, strings, arguments, set container, map container

Guess you like

Origin www.cnblogs.com/yaokai729/p/11370160.html