سؤال

In browser there is a handy way of checking what kind of object you are dealing with by writing following code:

Object.prototype.toString.call([]); // "[object Array]"

In xPages SSJS

<xp:text escape="true" id="computedField1">
<xp:this.value>
<![CDATA[#{javascript:Object.prototype.toString.call([]);}]]>
</xp:this.value>
</xp:text>

When I'm doing the same thing in xPages SSJS I'm getting following error message:

Error calling method 'call(Array)' on an object of type 'function [JavaScript Object]'

Why am I getting this error in xPages SSJS and is there a way to get around it?

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

المحلول

Every global object or variable in SSJS is an object of a class defined in Java. The statement

Object.prototype.toString.call([]); 

is for JavaScript not for Java. That's why the error. If you wish to find out the class to which the object belongs in SSJS then you can call .getClass().getName().

obj.getClass().getName()

You can find more information here.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top