Javascript instanceof & typeof in GWT (JSNI)
Posted
by rybz
on Stack Overflow
See other posts from Stack Overflow
or by rybz
Published on 2010-05-31T13:27:41Z
Indexed on
2010/05/31
13:33 UTC
Read the original article
Hit count: 283
Hi, I've encountered an curious problem while trying to use some objects through JSNI in GWT. Let's say we have javscript file with the function defined:
test.js:
function test(arg){
var type = typeof(arg);
if (arg instanceof Array)
alert('Array');
if (arg instanceof Object)
alert('Object');
if (arg instanceof String)
alert('String');
}
And the we want to call this function user JSNI:
public static native void testx()/ *-{
$wnd.test( new Array(1, 2, 3) );
$wnd.test( [ 1, 2, 3 ] );
$wnd.test( {val:1} );
$wnd.test( "Some text" );
}-*/;
The questions are:
- why
instanceof
instructions will always returnfalse
? - why
typeof
will always return"object"
? - how to pass these objects so that they were recognized properly?
© Stack Overflow or respective owner