javascript - Spread Operator ... 与 Material UI 中 Tab 的 props 中的函数调用一起使用
问题描述
我<Tab label="Item One" {...a11yProps(1)} />
在 Material UI 中看到了这一点,其中函数在道具中使用 ... 展开运算符调用当我尝试时
console.log(...a11yProps(3));
我得到错误,任何人都可以告诉这里发生了什么<Tab label="Item One" {...a11yProps(1)} />
传播运算符如何与函数调用一起使用?
解决方案
演示
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);
推荐阅读
- python - Python 四位密码查找器
- r - (R) 错误:未使用的参数(禁止 = 表达式(x2 > x1))
- php - 如何使用 PHP 开发工具包创建具有对 S3 的完全访问权限的编程访问权限的 IAM 用户
- javascript - 我在使用 Javascript 和 PHP 将函数分配给 SweetAlert 时出错
- email - MsGraph WebAPI 访问共享邮箱
- urlencode - Rest Sharp 转义 %5F 字符
- database - 为什么在区块链中查询(即读取数据)很慢?
- python - 如何计算 Django 中客户的余额?
- node.js - 如何在一个会话中保存身份验证以使用 AdonisJS 5 在其他页面中检索?
- android - 如何使用表情符号作为可绘制对象来显示五彩纸屑?