W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2012

Re: Detecting the "type" of a DOM object

From: Marat Tanalin | tanalin.com <mtanalin@yandex.ru>
Date: Thu, 07 Jun 2012 17:08:52 +0400
To: Boris Zbarsky <bzbarsky@mit.edu>
Cc: David Bruant <bruant.d@gmail.com>,"public-script-coord@w3.org" <public-script-coord@w3.org>
Message-Id: <768401339074532@web30h.yandex.ru>
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

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:06 UTC