prototype: Fix Class#addMethods for "toString" and "valueOf" methods in Internet Explorer. Closes #9901.
This commit is contained in:
parent
b14c9afa58
commit
9b78edb9de
|
@ -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]
|
||||
|
|
12
src/base.js
12
src/base.js
|
@ -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) {
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue