Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Depends on <em>what</em> you want to inherit. I find that if I use the JavaScript prototype for object “definitions” I get the static methods of Java objects only:</p> <pre><code>function test() { this.hello = function() { for(var i in this) { println(i); } }; } test.prototype= com.acme.app.TestClass; // use your class with static methods // see the inheritance in action: var testInstance=new test(); test.hello(); </code></pre> <p>However, JavaScript allows you to do prototype assignments on object instances as well, so you could use a function like this, and get a more Java-like inheritance behaviour:</p> <pre><code>function test(baseInstance) { var obj = new function() { this.hello=function() { for(var i in this) { println(i); } }; }; obj.prototype=baseInstance; // inherit from baseInstance. } // see the thing in action: var testInstance=test(new com.acme.TestClass()); // provide your base type testInstance.hello(); </code></pre> <p>Or use a function (e.g. <code>init</code>) similar to the above function in the object itself:</p> <pre><code>function test() { this.init=function(baseInstance) { this.prototype=baseInstance; }; this.hello=function() { for(var i in this) { println(i); } }; } var testInstance=new test(); println(typeof(testInstance.prototype)); // is null or undefined testInstance.init(new com.acme.TestClass()); // inherit from base object // see it in action: println(typeof(testInstance.prototype)); // is now com.acme.TestClass testInstance.hello(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload