gpt4 book ai didi

javascript - 无法在 GWT : "delete" method name treated as keyword? 中使用 JS (Harmony) WeakMap

转载 作者:行者123 更新时间:2023-11-30 12:43:16 27 4
gpt4 key购买 nike

我正在尝试在 JavaScript WeakMap 上构建 GWT 包装器。 WeakMap API 定义了一个名为“delete”的方法(例如参见 here)。但是使用这种方法会导致 GWT 中出现编译错误:

...
[INFO] [ERROR] Line 77: missing name after . operator
[INFO] > this.map.delete(key);
...

看起来(对我来说) 好像 GWT 编译器 (gwt-maven-plugin v2.6.0) 将所有出现的单词“delete”解释为“关键字”。

我该如何解决这个问题?

...
private native void init()
/*-{
this.map = new window.WeakMap();
}-*/;

/** Constructor */
public MyWeakKeyMap() {
init();
}
...
public native VALUE remove(final Object key)
/*-{
var result = this.map.get(key);
this.map.delete(key);
return result;
}-*/;
...

最佳答案

我找到了一种绕过它的方法,它在 GWT 中编译:

private native void init()
/*-{
this.map = new $wnd.WeakMap();
this.map.rmv = this.map['delete'];
}-*/;
public native VALUE remove(final Object key)
/*-{
var result = this.map.get(key);
this.map.rmv(key);
return result;
}-*/;

关于javascript - 无法在 GWT : "delete" method name treated as keyword? 中使用 JS (Harmony) WeakMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23581459/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com