如何通过Dart中的Mirrors调用operator-array-function

时间:2015-07-15 14:41:35

标签: dart dart-mirrors

这适用于Dart-VM:

final List<String> names = [ "Bob", "JOE" ];
final InstanceMirror instanceMirror = reflect(names);

final Symbol function = new Symbol("[]");

final InstanceMirror getField = instanceMirror.invoke(function,[ 1 ]);
context = getField.reflectee;
_logger.info("Value $context"); // Shows JOE

但是如果我把它编译成JS就失败了。 错误消息:`NoSuchMethodError:找不到方法:'[]'接收方:'JSArray'参数的实例:[1]'

我也尝试过使用elementAt而不是[],然后我得到Unsupported operation: Can't use 'elementAt:1' in reflection because it is not included in a @MirrorsUsed annotation.

0 个答案:

没有答案