Re: isElement - determining if an object is an element
- From: David Mark <dmark.cinsoft@xxxxxxxxx>
- Date: Thu, 31 Jul 2008 09:55:27 -0700 (PDT)
On Jul 31, 11:07 am, "Aaron Gray" <ang.use...@xxxxxxxxx> wrote:
"kangax" <kan...@xxxxxxxxx> wrote in message
news:43fd545a-5e4c-4df8-a951-f8cb04ede4f6@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jul 30, 11:52 am, "Aaron Gray" <ang.use...@xxxxxxxxx> wrote:
[snip]The double function expression is unnecessary.
It could be rewritten like so:
var isElement = (function(){
var el = document.createElement('div'), fn;
if (Element && el instanceof Element) { // Thanks RobG> fn = function(o) {
return o instanceof Element;
}
}
else {
fn = function(o) {
return o && 'nodeType' in o && o.nodeType === 1;
}
}
el = null;
return fn;
})();
We don't perform such branching in prototype.js to avoid
inconsistencies across browsers.
LOL.
Right. Is the inconsistancy really that bad as to cause problems with an
example like this ?
You and the Prototype guy are both trying to solve the same problem
that does not need to be solved. Nobody need a GP function to
discriminate between an Object object and an element.
isElement(document.createElement('div')); // true in IE and FF
isElement({ nodeType: 1 }); // true in IE, but false in FF
Yes this is the sort of behaviour that I was trying to avoid, hence adding
in the 'typeof o.tagName === string' to make the test stricter.
If IE had followed the other browsers and made browser types first class we
would not have these problems.
We don't have a problem. It is people who wish to make the language
work more like Java who have a problem. The problem is easily
diagnosed: they do not understand the language they are using or
browser scripting in general.
.
- References:
- isElement - determining if an object is an element
- From: Aaron Gray
- Re: isElement - determining if an object is an element
- From: Henry
- Re: isElement - determining if an object is an element
- From: Aaron Gray
- Re: isElement - determining if an object is an element
- From: Aaron Gray
- Re: isElement - determining if an object is an element
- From: kangax
- Re: isElement - determining if an object is an element
- From: Aaron Gray
- isElement - determining if an object is an element
- Prev by Date: Re: isElement - determining if an object is an element
- Next by Date: Re: isElement - determining if an object is an element
- Previous by thread: Re: isElement - determining if an object is an element
- Next by thread: Re: isElement - determining if an object is an element
- Index(es):
Relevant Pages
|