I am trying to use JSNI (gwt's javacript interface) to set/get variable to/from js object:window like this:
private final native <T> T get(String key)/*-{
return $wnd.key;
}-*/;
private final native void set(String key, Object value)/*-{
$wnd.key = value;
}-*/;
///// js equivalent should like this
function get(String key){
return window.key;
}
function set(String key, var value){
window.key = value;
}
and if I set a variable: var_1 to window:
var var_1={"id":"id_1","name":"name_1"}
set("key_1",var_1)
then
get("key_1")
I will get var_1 correctly
and then set another variable var_2 to window
var var_2={"id":"id_2","name":"name_2"}
set("key_2",var_2)
then,try to get key_1 again
get("key_1")
unexpectedly,var_2 will be returned
so,the problem is obvious:the get() function will always return the last set variable no matter what key is.Questions are:
1,Why?
2,How to make it right?