1, the function parameter's default value
ES5 cannot directly specify a default value for a function's arguments, only the following workarounds can be used:
From the above code you can see that there is a problem, when the passed parameter is 0 or FALSE, it will be taken directly to the subsequent value, rather than the incoming parameter value.
So how do we solve it? For the code above, you can determine whether to pass in the NUM parameter without using the default value:
This is still cumbersome, and ES6 sets the default value of the function parameter directly in the parameter definition, without worrying that the incoming argument is 0 or false:
2. Arrow function
The arrow function is defined with the => symbol.
The arrow function is equivalent to an anonymous function, so the function expression is used.
On the left is the parameters of the passed function, and the right is the statement executed in the function.
The above is the complete writing, the left parenthesis, the right curly brace, and the following situation can be abbreviated:
(1) When the code block to be executed has only one return statement, the curly brace and return keyword can be omitted:
The arrow function is very concise in the callback function, like this:
Note that the arrow functions do not have their own this, arguments, super, and New.target, which point to the corresponding variable of the outer function respectively.
It's a bit of a hassle to use this in ES5 before, and this is a common problem:
But now that you have the arrow function, you no longer need to use that = this or _this = This code, because this in the arrow function is directly the this in the outer function, and the code is simpler:
The above is a small set to introduce a simple ES6 new characteristics of the function of the default parameters and arrow functions, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!