typescript - 我可以在 TypeScript 中将引用作为数组项传递吗?
问题描述
我想将数组中的引用传递给 JavaScript 中的函数,如下所示:
class MyClass {
// ...
myfunc(['str1', 'str2'], [this.companies, this.devizas, this.paymentTypes]);
// ...
}
inmyfunc
是这样的:
function myfunc(firstArg: string[], references: any[]): void {
const payload: any[] = [];
// payload's content coming from an observable and length will be equal to `reference` array
for (let i = 0; i < payload.length; i++) {
references[i] = payload[i];
// here I want to pass value payload[0] into the caller class this.companies field
}
}
现在——如果我认为正确的话——以这种方式,该references[i] = payload[i];
行将用一个值覆盖引用,而不是将值加载到引用中。
有没有办法在数组中传递引用并用值填充引用?
解决方案
推荐阅读
- android - 在android中将数据从一个应用程序发送到另一个应用程序的加密
- r - 在线图 r 中绘制分组变量
- excel - 使用 VBA 将单词与数字分开
- java - 如何从左到上更改 Android TV 应用中标题的位置?
- android - 如何使用向量打印文件中的单词列表,每次用户查询 [C++] 一次?
- powershell - ms access.exe挂起powershell时发送电子邮件
- sql - SQL 嵌套 IIF 函数
- cassandra - cassandra-reaper:维修一再推迟和卡住
- android - AdMob 永远不会在某些设备上加载
- google-maps - 谷歌静态地图不显示超过 5 个图钉