Using CreateObject( ) to expose a POD to JavaScript engine

The JavaScript avantgo.createObject() method returns a PODS object exported by a POD currently loaded in M-Business Client. This function queries all loaded PODS modules, passes the name to each, and asks each if it can provide an object in return. avantgo.createObject() either returns a PODS object, or if no POD can provide an object with the given name, it returns NULL. The synopsis is:

CreateObject(name)

The name argument is a string containing the name of the object or type of object to return.

Most PODs interpret a name passed to avantgo.createObject() as a class name (in other words, the name of a type of object) and create a new object instance for each call to avantgo.createObject(). For example, Acme Network Company might create a POD used for network communication that can provide objects of the class "Acme.Socket". When this POD is present on a mobile device, a JavaScript author could call CreateObject("Acme.Socket") to create a new socket object used for network communication. Each successive call to CreateObject("Acme.Socket") would create an entirely new socket.

Other PODs may interpret a name passed to CreateObject() as the name of a single object that the POD can return to JavaScript. For example, SuperBank Inc. might create a POD that stores checking information in an electronic checkbook on a handheld device. If there is only one checkbook per device, then the call CreateObject("SuperBank.Checkbook") could return it. Successive calls to CreateObject("SuperBank.Checkbook") would return the same, unique Checkbook object.

The method name, CreateObject(), reflects the fact that many PODs create a new object in response to each call to this method. If you are writing JavaScript code that calls a POD and you did not write the POD, you should consult the POD's author or documentation to find out whether the POD creates a new object on each call to CreateObject().

The example below shows that JavaScript code can access a PODS object's properties (for example, checkbook.balance) or methods (for example, checkbook.update()), just as it can access properties or methods of any other object. In the example, when JavaScript calls checkbook.update() or accesses the checkbook.balance property, M-Business Client calls the POD, which implements the method and property using native code.

<SCRIPT> 
checkbook = CreateObject("SuperBank.Checkbook"); 
</SCRIPT> 
... 
<INPUT type="text" name="mytext"> 
<INPUT type="button" name="update" onClick="checkbook.update()"> 
<INPUT type="button" name="balance"
    onClick="document.myform.mytext.value = checkbook.balance">