prototype: Fix Class#addMethods for "toString" and "valueOf" methods in Internet Explorer. Closes #9901.

This commit is contained in:
Sam Stephenson 2007-11-06 01:44:24 +00:00
parent b14c9afa58
commit 9b78edb9de
3 changed files with 25 additions and 4 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Fix Class#addMethods for "toString" and "valueOf" methods in Internet Explorer. Closes #9901. [sam]
* Exclude Opera from using the sourceIndex approach in Element#descendantOf. [Tobie Langel, Andrew Dupont]
* Ensure Element#hasClassName always returns a boolean. Closes #10075. [ronnylovtangen, Tobie Langel]

View File

@ -34,10 +34,14 @@ var Class = {
Class.Methods = {
addMethods: function(source) {
var ancestor = this.superclass && this.superclass.prototype;
for (var property in source) {
var value = source[property];
var ancestor = this.superclass && this.superclass.prototype;
var properties = Object.keys(source);
if (!Object.keys({ toString: true }).length)
properties.push("toString", "valueOf");
for (var i = 0, length = properties.length; i < length; i++) {
var property = properties[i], value = source[property];
if (ancestor && Object.isFunction(value) &&
value.argumentNames().first() == "$super") {
var method = value, value = Object.extend((function(m) {

View File

@ -599,6 +599,21 @@
assertEqual('#<Ox: cow>', cow.inspect());
assertRespondsTo('reproduce', cow);
assertRespondsTo('getValue', cow);
}},
testClassWithToStringAndValueOfMethods: function() { with(this) {
var Foo = Class.create({
toString: function() {
return "toString";
},
valueOf: function() {
return "valueOf";
}
});
assertEqual("toString", new Foo().toString());
assertEqual("valueOf", new Foo().valueOf());
}}
}, 'testlog');