-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Description
Description
Our style guide says that we identify DOM elements with (Boolean) object.nodeType, but that's not exactly true. We actually use it to identify DOM nodes, but even setting aside semantics, there is a case where an object with a truthy nodeType property can avoid the DOM node path: setting data.
This means that .data can succeed or fail based on some rather trivial differences, which makes me uncomfortable. We should have a single "is DOM node" test, applied consistently everywhere. nodeType will always have certain characteristics on real DOM nodes (existence, "number" type, integer, positive), but we can use any subset thereof—I'm leaning towards typeof obj.nodeType === "number" or obj && "nodeType" in obj, because any given kind of input seems unlikely to change classification. And whatever we pick, the style guide will also need an update.
A macro would be really nice, because it seems silly not to inline such trivial code, but I think we can continue to live without something like sweet.js for now.