On Oct 12, 3:29 am, "Justin Perkins" <[EMAIL PROTECTED]> wrote:
> On Sat, Oct 11, 2008 at 10:31 AM, RobG <[EMAIL PROTECTED]> wrote:
> > Performance is not the issue - fewer lines of code doesn't necessarily
> > mean faster performance.
>
> Do you differentiate between browser sniffing and object/method sniffing?
As far as I am aware, there is no such thing as "object/method
sniffing", it's called object/feature detection. Browser sniffing is
using the user agent string or similar to distinguish a particular
browser. Object or feature detection is using a test to see if a
particular object or feature is supported. It is much more robust and
requires far less maintenance.
> Do you like that Prototype's Selector#findElements method uses XPATH
> (Firefox) and querySelector/querySelectorAll (WebKit) when available?
Yes, I just don't like the way it goes about deciding which method to
used.
> Or do you think this muddles up the codebase with unnecessary
> branching?
Not necessarily. Branching can be avoided where it matters (usually
for performance reasons) - the feature test need only be carried out
once and an appropriate method assigned to the identifier that will be
used to call it. e.g.
var someMethod = (function () {
if ( featureTest ) {
return function() { /* function using feature */ };
} else {
return function() { /* alternative function */ };
}
})();
Sometimes you have to wait until the DOM is ready before you can do
the test, or a body element exists, etc. In those cases, bottom-
loading the script helps. Some functions are not called often enough
to make it worthwhile.
> (not trying to get into a huge discussion, just curious where you draw the
> line)
Browser sniffing can nearly always be avoided, sometimes it takes a
bit of time and effort to work out an appropriate test. I find that
once programmers start sniffing, it's very easy to become lazy and
depend on it when fairly simple alternatives exist.
For example, a little while ago (12 months?) jQuery had 17 browser
sniffs, it now has 30. I haven't counted how many there are in
Prototype.js.
--
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---