How to handle objects with length of one and greater than one in a method without redunancy
<p>I'm writing my own JavaScript bind method (for practice) and am having trouble letting go of the need to handle single objects vs multiple objects differently in this method, solely because I need to loop through objects with a length greater than one. (see obj vs obj[i] below)</p>

<p><strong>Is there any way I can make this bind method less redundant feeling?</strong> (please assume using another library is out of the question.. thanks)</p>

<pre><code>var foo = (function () {
    return {
        bind: function (obj, type, handler, delegate) {
            var delegate = delegate || false,
                len = obj.length;
            if (typeof obj == 'undefined') {
                return false;
            }
            if (len &gt; 1) {
                for (var i = 0; i &lt; len; i++) {
                    if (obj.addEventListener) {
                        obj[i].addEventListener(type, handler, delegate); // false: bubble (^). true: capture (v).
                    } else if (obj.attachEvent) {
                        obj[i].attachEvent('on' + type, handler);
                    } else {
                        obj[i]['on' + type] = handler;
                    }
                }
            } else {
                if (obj.addEventListener) {
                    obj.addEventListener(type, handler, delegate); // false: bubble (^). true: capture (v).
                } else if (obj.attachEvent) {
                    obj.attachEvent('on' + type, handler);
                } else {
                    obj['on' + type] = handler;
                }
            }
        }
    }
})();
</code></pre>
