Any sufficiently advanced technology is indistinguishable from magic. | |
Arthur C. Clarke |
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:
Java Language API. . As we have seen in .js generated files, the object Clazz contains methods for that emulates the java language leting the javascript programmer to declare java elements like package, classes, methods and so on.
Java Runtime API. . As we have seen in the html files generated by Java2Script when we run a J2S application, the ClazzLoader object contains an API for configuring the java runtime, for example, leting the javascript programmer configure the "java classpath", loading a set of classes and executing some java code when those classes are available.
In this chapter we try to document the relevant API functions of this two javascript objects.
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???
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 |