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+