So I had this little javascript method that I was using to hide stuff on my web page. (This version is slightly modified -- hopefully I didn't add too many bugs):

Code JavaScript:
    function hide(arg) {
        if((arg instanceof Array) || (arg instanceof HTMLCollection))
            var elemList = arg;
            var elemList = [ arg ];
        for(var i = 0; i < elemList.length; ++i)
            elemList[i].style.display = 'none';

Somtimes I was passing single DOM elements, but other times I was passing a list of them either as an Array or as an HTMLCollection. Two usages were as follows:

Code JavaScript:

This worked great for a while, but apparently the powers-that-be decided the storage class HTMLCollection just wasn't cutting it and calls to getElementsByName one day started returning a new data type: NodeList, which of course broke my script.

I don't have much experience with Javascript (or any other weakly typed language for that matter). It occurs to me that what I'm really trying to do is come up with a substitute for the technique of function overloading that folks use in Java or C++ (strongly typed languages). In those languages I would have two methods doSomething -- one that took a list, and the other that took a single instance. And in those languages, you wouldn't have the return type of core library methods change on you.

So my questions are:

1) Should I just be abandoning this technique of interrogating argument types to achieve what is basically a function overload? Should I instead restrict myself to having two methods: hide() and hideList() (which seems rather cumbersome given my background)?

2) Or is there some more robust way I could have written my original hide method such that it wouldn't have failed and that is in general a better way to achieve function overloading?

Thanks much,