Ticket #289 (new enhancement)

Opened 8 months ago

Testing function MochiKit.DOM.isDOM is needed for creating a repr-function

Reported by: Per Cederberg <cederberg@gmail.com> Assigned to: somebody
Priority: normal Milestone: MochiKit 1.5
Component: component1 Version:
Severity: normal Keywords: api
Cc:

Description

When creating a repr-function for DOM nodes (using a non-recursive emitHTML), I needed the following function:

    /** @id MochiKit.DOM.isDOM */
    isDOM: function (obj) {
        return typeof(obj) != "undefined" &&
               typeof(obj.nodeType) == "number" &&
               obj.nodeType > 0;
    },

I think it is useful, since similar tests are used several times inside the MochiKit.DOM implementation. Here is the suggested rst documentation:

:mochidef:`isDOM(obj)`:

    Returns ``true`` if ``obj`` looks like a DOM node, otherwise
    returns ``false``. Any non-null object with a numeric
    ``nodeType`` attribute > 0 will be assumed to be a DOM node by
    this function (and several others in the MochiKit.DOM API).

    *Availability*:
        Available in MochiKit 1.5+