Can someone provide me an example on how to extend a java class in java script using Rhino's java adapter ?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Depends on what 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:
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:
Or use a function (e.g.
init
) similar to the above function in the object itself:Since I am not a 100% sure that by Java Adapter you mean what I think it is, Java interfaces and such can be created with property lists (name = function()):
Or alternatively for single-method things like that:
For anyone else who might come across this, there's a decent example here (the author uses it to extend
awt.Canvas
).There's more information on MDN, including a brief explanation and calling syntax example.
E.g. starting a thread in Rhino: