Simple javascript question.

(I posted this in a javascript forum, but there seems to be a problem with the site. I know you guys can help)

Isn’t there a pre-defined ‘isObject’ function in javascript? I’ve found some references to it, but I can’t get it to work.

I am trying to determine if a window exists, with the isObject function if it does I want to close it.

This code –

If (isObject(test)){
test.close()
}

Produces the error ‘test is undefined’

Everything I’ve read says it should return ‘false’ if it’ s undefined.

If (!(isUndefined(test))){
test.close()
}

Returns the same error.

Thanks

I do not believe isObject/isUndefined is standard Javascript. In fact I’ve never seen those before.

What you want is


if(typeof test == 'object') // test if it's an object
{
       test.close();
}

if(typeof test == 'object' && a) // tests if it's not null
{
       test.close();
}
if(!(typeof test == 'undefined')) // tests if it's defined
{
       test.close();
}



Note: I haven’t tested that so caveat emptor

Thanks much, looks like that will do it.