![](/img/trans.png)
[英]How to call a JavaScript function from GWT with jsInterop?
[英]GWT JsInterop - call an object like it's a function
使用JsInterop,我包裝了以下JavaScript代碼:
var voronoi = d3.geom.voronoi()
.clipExtent([[0, 0], [width, height]]);
如下:
private Voronoi voronoi;
...
voronoi = d3.geom().voronoi()
.clipExtent(new Double[][] {{0.D, 0.D}, {width, height}});
這似乎在起作用。
稍后,在JavaScript方面,他們進行了以下調用:
path = path
.data(voronoi(vertices), polygon);
我很難弄清楚如何調用voronoi實例,就好像它是這種功能一樣。
在本文檔中: https : //docs.google.com/document/d/10fmlEYIHcyead_4R1S5wKGs1t2I7Fnp_PaNaa7XTEk0/edit# ,我看到以下行:
@JsFunction JsInterop的另一個強大功能是能夠表示Java和JavaScript之間的JavaScript函數協定。 這意味着可以輕松地從Java調用JavaScript函數,或者可以像JavaScript中的函數一樣調用Java對象:
現在,我的Voronoi對象如下:
@JsType(isNative = true)
public interface Voronoi extends Geometry {
<D> Voronoi clipExtent(D[][] bounds);
}
我有什么想法要把我的Voronoi實例稱為函數嗎?
謝謝
@JsType(isNative = true)
public interface Voronoi extends Geometry {
@JsMethod
static native [TheTypeItReturns] call(Voronoi self, [ParameterTypes]... args);
<D> Voronoi clipExtent(D[][] bounds);
}
查看https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call和https://developer.mozilla.org/en-US/docs/Web/JavaScript/參考/ Global_Objects / Function / apply 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.