Try/catch is almost never required, and is overused, or used in more general ways than required for efficient code branching. As regards this new native function, a simple test will suffice (in most cases):
Code:
if (document.getElementsByClassName){
do stuff here that uses it
}
else {
do something else that takes care of it
}
It is a little more complicated than that sometimes because getElementsByClassName functions exist, their syntax and capabilities can still be tested against the standard though to tell whether or not they're up to the situation at hand. If they are, might as well use them, if not - go for your own custom function.
That way your code will benefit from the efficiency of the native and/or existing function, while still being able to execute in the absence of either.
I know, you're right - in actual practice it can be a pain. But that is what must be done any time a new native function (that already had popular approximations in a variety of scripts) is introduced. Over time (in most cases) though, it becomes a standard. At that point backward compatibility can usually be safely abandoned.
In actual practice though, the simple test I provided will work 99% of the time because few scripts will use Element.prototype (supported only by some browsers) to spoof getElementsByClassName, which would be required to satisfy the test in the absence of a native getElementsByClassName.
Bookmarks