"not an object"

yikes aroni yikesaroni at gmail.com
Tue May 31 20:23:16 UTC 2016


So from a javascript function i call a java method that returns a java
object. What gets returned is not a simple bean. It has properties and
methods on it.

var xxx = MyJavaClass.getMeSomething();

The *typeof* xxx is "object" according to Nashorn. However, when i try to
do things with it -- as if it were a Javascript object -- I get the message

TypeError: testSample is not an Object

Is there something specific i need to do to be able to manipulate xxx as a
javascript object? For example, I want to be able to add properties and
functions to it

xxx['someProp'] = 3.14;
xxx['someFn'] = function() {
     print('hello!');
}

I want to be able to get stuff from it

Object.getOwnPropertyNames(xxx).forEach(function(val) { print(val) });

Stuff like that... but i can't because it's not seen as a native JS
"object"

thanks. I hope i am clear.


More information about the nashorn-dev mailing list