javascriptjavagwtjsnifacebook-instant-games

GWT compiler isn't allowing 'default' as a javascript object property in my JSNI block


I'm porting my Java LIBGDX game to Javascript. There's some JSNI code that looks something like this:

private native void hello()
/*-{
    var object1 = {default: 'foo', b: 42};
    console.log(object1.default);
}-*/;

GWT refuses to compile this, giving me this error:

      [ERROR] Line 38: invalid property id
>       var object1 = {default: 'foo', b: 42, c: {}};
> ------------------------^

I tried the same code in native Javascript here and it works fine.

I'm guessing 'default' is some kind of keyword that GWT isn't allowing but I need to use it, because its expected by the interface I need to send the object to, specifically the Facebook Instant SDK and its LocalizableContent object.

Any help will be appreciated!


Solution

  • Make it a string rather than an identifier:

    private native void hello() /*-{
        var object1 = {'default': 'foo', b: 42};
        console.log(object1['default']);
    }-*/;