ES6 new syntax of Default Function Parameters
Default Function Parameters.md
Default Function Parameters
In ES5,if the argument is not specified,its value would be set to undefined.
if we do this,what will be happen?
if this?
function getSum(a, b) {console.log( a + b); } getSum(); getSum(1,2); getSum(10); getSum(null, 6); //ES6 function getSum(a = 1, b = 41 ) {console.log(a + b); }getSum(); getSum(1, 2); getSum(10); getSum(null, 6);
In ES6 sets default values trying to streamline this process.
How to check the numbers of the arguments?
we can check the numbers of the arguments by arguments.length.
Even thougn the second argument get a default value, arguments.length only returns the number of arguments passed to it.
var getPrice = function(quantity = price, price = 5){console.log(quantity + " ," + price); }getPrice();
This is a TDZ reference Error.
Because the parameters scope just between the parentheses(...).It isn't in a function body scope.
dynamic function
summary
the type of default arguments
1.set a default value to the parameter in the function declaration statement itself.
2.function default values can be any valid expression.
3.function call
4.We can also access the other variables in the expression used as the default value.
Question what is dynamic function?
轉(zhuǎn)載于:https://www.cnblogs.com/InnerPeace-Hecdi/p/8870632.html
總結(jié)
以上是生活随笔為你收集整理的ES6 new syntax of Default Function Parameters的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 01-sql优化及索引
- 下一篇: SQL SERVER 存储过程执行带输出