2011-04-08 65 views
1

我不是JS开发人员,但我想了解由GWT编译器转换为JS的Java代码在我们的大型应用程序中找到增加内存的原因的方式。了解GWT编译器输出

一段时间我看到一些变量,assigened为“_”,例如

_ = com_google_gwt_event_shared_GwtEvent.prototype = new java_lang_Object; 

这些类型的任务是在代码中的许多地方。这是什么意思 ?

回答

3

GWT编译器使用JavaScript prototype chains对Java类型层次结构进行建模。 _符号被编译器和简短的JSNI方法用作全局临时变量。在生成的脚本的顶部范围,你应该看到类似

// Define the JS constructor(s) for the type 
function com___GwtEvent() {} 
// Inherit methods from the supertype by prototype chain 
_ = com___GwtEvent.prototype = new java_lang_Object; 
// Attach polymorphically-dispatched methods to the new type 
_.someInstanceMethod = function(a,b,c){.....} 
// Static-dispatch methods 
function $someOtherMethod(this$static, d, e) {...} 

如果你看到有一个this$static参数的方法,编译器已经推断出Java表达式instance.someOtherMethod()并不多态(可能通过型紧缩)并避免运行时中间符号查找的开销。