On 12/27/12 2:18 AM, Boris Zbarsky wrote:
The arguably "right" way to do the "el instanceof HTMLAnchorElement"
test is:
el instanceof el.ownerDocument.defaultView.HTMLAnchorElement
Needless to say this sucks.
Eew, indeed.
So the question is how we should make the above work sanely. [...]
Other ideas?
Hmm. My first reaction is to gently challenge if this really has to
change, or if it can't be beaten into submission by some other deep
magic hack...
After all, if it's changing a frequently used chrome/addon pattern,
that's a pretty big incompatibility step. And I'd sort of expect an
HTMLAnchorElement to always be an HTMLAnchorElement, without the
creator's context mattering... [1]
But I don't understand the problem space well, so I'll just accept for
the moment that it really really does need to change. :)
One fairly easy (and mechanical?) option would be to add a global helper
function. Something roughly along the lines of:
var isIt = checkForDOMInterface(el, "HTMLAnchorElement");
function checkForDOMInterface(el, kind) {
return (e instanceof el.ownerDocument.defaultView[kind]);
}
That wouldn't be too terrible to do, and is easy to communicate.
A bigger shift might be to change to using existing properties
(.nodeName? .nodeType?) or add something new?
[1] Tangential curiosity on that expectation... What happens today (and
in the future), with something like:
// Hello, I am chrome code adding an anchor to content
var noob = document.createElement("a");
gBrowser.contentDocument.body.appendChild(noob);
// ...later, for an arbitrary node, possibly el === noob
var isAnchor = el instanceof HTMLAnchorElement;
Justin
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform