Javascript instanceof & typeof in GWT (JSNI)
- by rybz
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 return false?
why typeof will always return "object" ?
how to pass these objects so that they were recognized properly?