diff --git a/CHANGELOG b/CHANGELOG index 77bb59d..40bda7d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Ensure `toString` and `valueOf` properties are copied to a subclass only when necessary in IE6. [@382 state:resolved] (Samuel Lebeau) + * Make sure `getAttribute` is used without flag when accessing the "type" attribute of an iframe (IE throws error otherwise). [#118 state:resolved] (Zekid, kangax) * String#gsub should escape RegExp metacharacters when the first argument is a string. [#469 state:resolved] (michael, kangax) diff --git a/src/lang/class.js b/src/lang/class.js index 0e3bd4a..2c335c9 100644 --- a/src/lang/class.js +++ b/src/lang/class.js @@ -83,7 +83,16 @@ var Class = (function() { if (!Object.keys({ toString: true }).length) properties.push("toString", "valueOf"); - + + // IE6 doesn't enumerate toString and valueOf properties, + // Force copy if they're not coming from Object.prototype. + if (!Object.keys({ toString: true }).length) { + if (source.toString != Object.prototype.toString) + properties.push("toString"); + if (source.valueOf != Object.prototype.valueOf) + properties.push("valueOf"); + } + for (var i = 0, length = properties.length; i < length; i++) { var property = properties[i], value = source[property]; if (ancestor && Object.isFunction(value) && diff --git a/test/unit/class_test.js b/test/unit/class_test.js index 98e8e88..8c5e9c3 100644 --- a/test/unit/class_test.js +++ b/test/unit/class_test.js @@ -112,6 +112,10 @@ new Test.Unit.Runner({ toString: function() { return "toString" }, valueOf: function() { return "valueOf" } }); + + var Bar = Class.create(Foo, { + valueOf: function() { return "myValueOf" } + }); var Parent = Class.create({ m1: function(){ return 'm1' }, @@ -126,5 +130,7 @@ new Test.Unit.Runner({ this.assertEqual("toString", new Foo().toString()); this.assertEqual("valueOf", new Foo().valueOf()); + this.assertEqual("toString", new Bar().toString()); + this.assertEqual("myValueOf", new Bar().valueOf()); } }); \ No newline at end of file