Re: Detecting the "type" of a DOM object

07.06.2012, 01:35, "Boris Zbarsky" <bzbarsky@MIT.EDU>:
>> šWhile it wouldn't be perfectly future-proof (since new subclass of Nodes
>> šcan come along later), the technique I've explained above does work
>> šacross globals.
>
> For the specific cast of Node... last I checked, there are 100+
> subclasses of Node in the platform, with new ones being added about
> monthly. šThe technique you described simply doesn't work for nodes....

FWIW: PHP has `is_a(object $object, string $class_name)` function [1] that checks if the object is of specific class OR has that class as one of its parents.

Probably, JavaScript should have a similar method sothat we could check, for example, if an object is a DOM node or an instance of one of its subclasses without (redundant and non-future-proof) need to go over each of existing subclasses explicitly.

[1] http://ru2.php.net/manual/en/function.is-a.php

Received on Thursday, 7 June 2012 13:09:26 UTC