When I define a static and a non-static function for Type in mobl.mobl, only the static function is recognized by the editor in Eclipse:

external Type {

static sync function foo() : void

sync function bar() : void

type MyType {}

var myType = MyType()

MyType.foo() // no error in editor

myType.bar() // error in editor, because it doesn’t recognize bar as a function of myType

But in javascript, it does work:

var myType = myModule.MyType()

myType.bar() // this works

Apparently instances of types are not recognized as a Type by the mobl editor from the Eclipse plugin.

Submitted by Volker on 23 March 2012 at 16:12
integrationtest.mobl23 March 2012 at 18:52

On 23 March 2012 at 17:54 chris melman commented:

external type Temp {

static sync function foo() : void

sync function bar() : void

screen root(){

var temp = Temp()

var x = Temp.foo() // no error in editor
var z = temp.bar()


works for me s what is the thing with Type,

what do you want to do with it?

On 23 March 2012 at 19:15 Volker commented:

Thanks for the quick reply Chris,

the ‘Type’ is the ‘external Type’ as defined in mobl.mobl from the mobl standard library (I forked the mobl-lib repository).

What I want to do is the following:
I want to send my types to my server. I made a simple example and included it as attachment (integrationtest.mobl) to help show what I mean.

It just tries to send a type to the server using a ‘service’ and ‘resource’. This does not work, because mobl stores (in its generated javascript) the actual data of a type in an object behind an attribute called ‘_data’. In order to pass the data to the $.ajax call (which the resource uses in its generated javascript), the data would first have to be retrieved (e.g. by calling Child._data in javascript).

Since this problem occurs with all types, I want to add a toJSON function to all types, which converts the type to a format that can actually be send to the server. The best way to achieve this would be to edit the already existing ‘external Type’ as defined in mobl.mobl in the mobl-lib, instead of copy-pasting the same method to all types I create.

It is possible to add a static function to the ‘external Type’, and it will be recognized as a function of all types I declare.
For example if I replace the original ‘Type’ from mobl.mobl in the mobl standard lib with:

external Type {

static sync function foo()


I can use the following code:

type Child{}


So I just added a static method to all types that will ever be created.

Now if I could create a non-static function toJSON for all types, I would be able to easily send types to my server by saying:

resource send(child : Child){



However, when I add a non-static method to the ‘Type’ form the mobl-lib it will not be recognized.

On 25 March 2012 at 12:15 chris melman commented:

I understand what you mean now,
as far as I can see and understand is this external Type pretty new in the mobl-lib and the function he used is commented out probably with reason that this wasn’t working propperly.

Did you have a look at the Type.fromJSON in the mobl.mobl maybe this one helps you out more

On 25 March 2012 at 14:44 Volker commented:

I did take a look at Type.fromJSON.
I actually uncommented it in my version of the mobl-lib and it worked perfectly.
That function inspired me to try and create a toJSON function.

The fromJSON function is a static function and static functions work, but for some reason non-static functions of ‘Type’ aren’t recognized by the editor (but they do work in the generated javascript).

I have worked around this issue by defining a static function like ‘MySerializer.toJSON(myType)’, written within mobl’s javascript tags, which uses the non-static Type.toJSON function I defined. Since mobl doesn’t do any type-checking within the javascript tags, the editor doesn’t give any errors. As stated before, the generated code does recognize the non-static function so it works perfectly.

Thanks to this workaround I can simply send my own types to the server using:

resource send( child : Child ) { data = MySerializer.toJSON(child) }

However, the fact that static functions of ‘Type’ are recognized by the editor, but non-static functions are not, seemed like an error in the editor’s type-checking (it doesn’t recognize instances of types as an instance of ‘Type’ as well).
It’s not a big problem, but it is something which could be fixed in a future release.

Log in to post comments