Appendix A. J2S Java Emulation API

 

Any sufficiently advanced technology is indistinguishable from magic.

 Arthur C. Clarke
Table of Contents
Java Language Emulation API
Java Runtime Emulation API

In this section we will examine Java2Script support for java emulation. When you include the j2slib.z.js script in your html documents Java2Script provides 2 types of APIs:

In this chapter we try to document the relevant API functions of this two javascript objects.

Java Language Emulation API

When including the script j2slib.z.js, there will be available the object Clazz that contains functions for "doing java" in javascript. We have already examine this kind of JavaScript code generated by J2S in the Section called Generated JavaScript files in Chapter 8.

a lot of documentation is at http://j2s.sourceforge.net/articles/oop-in-js-by-j2s.html. TODO: include that in this section???

Clazz.defineMethod = function (clazzThis, funName, funBody, funParams)

define a java method. the doc says:


  /*
 * Define method for the class with the given method name and method
 * body and method parameter signature.
 *
 * @param clazzThis host class in which the method to be defined
 * @param funName method name
 * @param funBody function object, e.g function () { ... }
 * @param funParams paramether signature, e.g ["string", "number"]
 * @return method of the given name. The method may be funBody or a wrapper
 * of the given funBody.
 */
/* public */
Clazz.defineMethod = function (clazzThis, funName, funBody, funParams)

example defining an instance method:
TODO

example defining a class method:
TODO