Bennett said:
Is there any way to find a string representing an object's class,
which will work in Internet Explorer 6?
No, since ECMAScript up to ed. 3 and thus JavaScript up to version 1.5
and JScript up to version 5.6 do not provide a class-based object model
but a prototype-based one.
It does.
it returns "object" for all objects:
As it is supposed to.
Have you declared the variable previously? If not, you better use the
`var' keyword here.
alert(typeof x);
And I found this page:
http://www.mozilla.org/js/language/js20-2002-04/core/expressions.html
which claims: "To get the type of an object x, use x.class".
ECMAScript 4 is yet to be standardized and JavaScript 2.0 to be the base
of it is yet to be implemented in UAs. If you would have read the above
thoroughly you would have noticed that there is still only one
implementation of ECMAScript 4 available -- Epimetheus. (Which could
become a prophetical choice since it is entirely possible that ECMAScript
4/JavaScript 2.0 will never be finished as AOLTW had temporarily closed the
Netscape browser division recently and, as probably a result, Netscape is
no longer a member of ECMA.)
However, that doesn't work in IE 6
IE resp. the Windows Script Host supports, among other script languages
like VBScript, JScript -- Microsoft's implementation of ECMAScript up to
ed. 3. So a JavaScript spec/doc is simply the wrong place to look, no
matter how current it is.
so it must be Mozilla-only.
It does not work in current Mozillas either.
That depends on what you are looking for and where. In ECMAScript 3 and
thus JavaScript 1.5 each object has a "constructor" property (inherited
from the Object prototype) referring to the constructor used to create the
object. Since that constructor function (in fact, *every* named function
statement) is also the definition for an object prototype, objects created
using the Foo() constructor can be referred to as "Foo objects".
window.open() returns a reference to a Window object if successful. One
could test for this in Gecko-based UAs with
if (x && x.constructor && x.constructor == Window)
{
// ...
}
But since window.open() never returns an object of a type different
from Window if successful and not every UA provides a public prototype
for all of its host objects (as Window objects are), that test appears
to be only academical. AFAIK
if (x)
{
// ...
}
always sufficed to date. If there are statements between the
window.open() call and the test, the latter should be changed to
if (x && !x.closed)
{
// ...
}
Both solutions have been pointed out to numerous times in this newsgroup
before. Please search before you post, see the FAQ.
PointedEars