鍍金池/ 問答/Android  HTML/ React中 arguments 和 props 的區(qū)別?

React中 arguments 和 props 的區(qū)別?

如題所述,看到一些教程里的代碼,大部分用的是super(props),但也有的地方是super (...arguments)

回答
編輯回答
病癮

props這樣只獲取到第一個參數(shù)
...arguments用了es6剩余參數(shù)可以獲取到所有的參數(shù)數(shù)組

function func1(props){
    console.log(props);
}
function func2(...arg){
   console.log(arg);
}
func1("a");  //a
func1("a","b","c");  //a
func2("a");  //["a"]
func2("a","b","c");  //["a","b","c"]
2017年11月17日 04:34