Questions about @JsProperty and JsType.prototype()

44 views
Skip to first unread message

田传武

unread,
Jul 1, 2014, 2:43:55 AM7/1/14
to google-web-tool...@googlegroups.com
Hi,
When i translate a pure java library to a javascript library using JsInterop, i get confused about @JsProperty and JsType.prototype().

The java code looks like this:
@JsType
@JsNamespace("$wnd.realtime.store")
public class TextInsertedEvent {

 
/**
   * The index of the change.
   */

 
public final int index;
 
/**
   * The inserted text
   */

 
public final String text;


 
/**
   * @param serialized The serialized event object.
   */

 
TextInsertedEvent(JsonObject serialized) {
   
this.index = (int) serialized.getNumber("index");
   
this.text = serialized.getString("text");
 
}


 
public int index() {
   
return index;
 
}


 
public String text() {
   
return text;
 
}
}






This TextInsertedEvent class is not allowed to be instantiated directly in javascript, so do not need to export its constructor.

When someone using the translated js library in a pure javascript web application:

1. How to prevent the prototype name from obfuscated?
e.g. realtime.store.TextInsertedEvent.isPrototypeOf(evt) should returns true
evt is a TextInsertEvent instance created from the translated library


2. How to translate to dotted property accessor instead of method calls?
e.g. enable users to call evt.text to get the actual string value, not evt.text()


Thanks for help :)
Reply all
Reply to author
Forward
0 new messages