prototypejs / prototype

Prototype JavaScript framework
http://prototypejs.org/
Other
3.54k stars 639 forks source link

Element.addMethods fails for method named as existing property #217

Open jwestbrook opened 10 years ago

jwestbrook commented 10 years ago

previous lighthouse ticket #1320 by Victor


See https://groups.google.com/forum/?pli=1#!topic/prototype-scriptaculous/WBYxj477_X4

The following code causes error in IE9 and fails silently in FF10:

document.observe('dom:loaded', function() {
    Element.addMethods("select", {
        size: function(element) {
            return element.select('options').size();
        }
    });
});

This happens because:

  1. Property size already exists for HTMLSelectElement in IE and FF
  2. destination[property] in mergeMethods() fails in IE for prototype of HTMLSelectElement and size
jwestbrook commented 10 years ago

Andrew Dupont March 4th, 2012 @ 07:55 AM

Yeah, this can't be helped, but we should document it better.