javascript - 如何创建对象作为参数?
问题描述
我有以下片段:
function click(...actions: any) {
const [ a, b, c ] = actions;
console.log(b);
}
let a = {
show: [
1, 2, 3, this.addService
]
};
click(a.show);
所以,我尝试a
通过 key在对象中添加一些变量show
。
然后我想获取这些参数并传递给函数click()。
然后在函数中,click
我试图获取 variables 中的所有参数[ a, b, c ]
。
我的问题在于:
show: [1, 2, 3, this.addService]
如何解决?
解决方案
从函数参数中删除扩展运算符。
function click(actions: any) {
const [ a, b, c ] = actions;
console.log(b);
}
let a = {
show: [
1, 2, 3, this.addService
]
};
click(a.show);
推荐阅读
- javascript - 如何在只读模式和输入模式之间切换html标签?
- php - Symfony 5.1 使用服务创建扩展
- django - 如何在 Django 中将对象属性从视图传递到模板?
- angular - ngbRadioButtonGroup 角度检查
- c# - 通过 json api 端点上传 base64 编码文件遇到状态码 400
- java - 如何检查 .doc 文件中是否存在任何嵌入对象?
- go - 从另一个模块导入包
- python-3.x - 这在 python 中的表中如何工作,以不同的变量命名每一列和每一行,还有其他选择吗?
- php - php中的关联数组值+ =
- c++ - 出队实现删除所有记录而不是前记录?