ES6 must know little knowledge

1. The default parameter function  

Generally, we set the default parameters to a function when the function will be used in such operator ||

function show(width,height ....){

  var height = height || 50;

  var width = width || 50;

    ....

}

There are drawbacks, such as a value of the parameter value is 0 then enter the function returns 0 for false || operation can imagine but who would use it if the argument is 0. . . . .

The syntax can be understood as es6 parameter can be directly assigned

function show(width = 50,height = 50....){

    ....

}

That's it

 

2 Template expressions

General string concatenation me what you are doing var name = "my name is" + name + "thank you!";

es6 Backticks can be wrapped with string, a $ {NAME} Syntax

var name = `my name is ${first} ${last} ! thank you`

 

3 es6 plurality of lines of character strings can also be used Backticks

es6之前  var str = ‘my name is’+name+'thanks'

        +'you name is'+name1+'thanks'

        +..............

 

es6 direct Backticks package

var str = `my name is ${first} thanks you name is ${name1} thanks`

 

 

To be more unfinished

Guess you like

Origin www.cnblogs.com/wgj-yzy/p/11099879.html