简体   繁体   中英

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. You'll have to write the lookup code yourself (eg using parallel arrays).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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