Spread Operator ... 在 material UI 的 Tab 属性中与函数调用一起使用
Spread Operator ... used with function call in props of Tab in material UI
我在 Material UI 中看到了这个 <Tab label="Item One" {...a11yProps(1)} />
,其中在道具中调用了函数 with ... spread operator 当我尝试 speratly as
console.log(...a11yProps(3));
我收到错误,任何人都可以知道这里发生了什么<Tab label="Item One" {...a11yProps(1)} />
展开运算符如何与函数调用一起使用?
就这样:
console.log(a11yProps(3));
演示
function fn(x, y, z) {
console.log("fn() called with", x, y, z);
}
let x;
x = ["a", "b", "c"];
fn( ...x ); //function call with spread of an array
console.log("spreading into an object", { ...x } ); // spreading into an object clones the properties of the array
x = {a: 1, b: 2, c: 3};
console.log("spreading into an object", { ...x } ); // spreading object into an object clones it
fn( ...x ); //spreading an object into a function call is an error
function fb2(){
return obj = {object : 'new Object'}
}
console.log({...fb2()}.object);
我在 Material UI 中看到了这个 <Tab label="Item One" {...a11yProps(1)} />
,其中在道具中调用了函数 with ... spread operator 当我尝试 speratly as
console.log(...a11yProps(3));
我收到错误,任何人都可以知道这里发生了什么<Tab label="Item One" {...a11yProps(1)} />
展开运算符如何与函数调用一起使用?
就这样:
console.log(a11yProps(3));
演示
function fn(x, y, z) {
console.log("fn() called with", x, y, z);
}
let x;
x = ["a", "b", "c"];
fn( ...x ); //function call with spread of an array
console.log("spreading into an object", { ...x } ); // spreading into an object clones the properties of the array
x = {a: 1, b: 2, c: 3};
console.log("spreading into an object", { ...x } ); // spreading object into an object clones it
fn( ...x ); //spreading an object into a function call is an error
function fb2(){
return obj = {object : 'new Object'}
}
console.log({...fb2()}.object);