简体   繁体   English

具有函数索引器的Typescript数组

[英]Typescript array with function indexer

I want to save some functions into an array and get them with the same function. 我想将一些函数保存到数组中并使用相同的函数。 Need a function or function reference, not string as indexer for an array. 需要一个函数或函数引用,而不是字符串作为数组的索引器。

myArray: SomeClass[] = [];
myArray[func].func = func;

Is this possible ? 这可能吗 ?

This is not possible as written. 按照书面规定,这是不可能的。 Property names in JavaScript are always strings. JavaScript中的属性名称始终是字符串。 You'll have to write the lookup code yourself (eg using parallel arrays). 您必须自己编写查找代码(例如,使用并行数组)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM