سؤال

Is there a secure way of doing this?

I tried

typeof {};
typeof someJavaObject;

But in both cases I am getting 'object'. I think this behavior is expected since all java objects are ScriptableObject, am I right?

So, then, how do I figure out if a variable refers to a javascript object (or a Java one)?

هل كانت مفيدة؟

المحلول

You can use someJavaObject instanceof java.lang.Object.

I would write a function though so it's clear what you're doing:

function isJavaObject(obj) {
    return obj instanceof java.lang.Object;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top