Fix toString/valueOf sharing same method reference via closure in Class#addMethods. Use plain property assignment, since Object.extend fails to enumerate over toString/valueOf.
This commit is contained in:
parent
637134651a
commit
64002a9083
|
@ -1,3 +1,5 @@
|
|||
* Fix toString/valueOf sharing same method reference via closure in Class#addMethods. Use plain property assignment, since Object.extend fails to enumerate over toString/valueOf. (kangax)
|
||||
|
||||
* Stop Form.Element.disable from stealing focus. (jddalton)
|
||||
|
||||
* Ensure Element.hide and Element.show return an element, even if you pass an element ID. (Andrew Dupont)
|
||||
|
|
11
src/base.js
11
src/base.js
|
@ -44,12 +44,13 @@ Class.Methods = {
|
|||
var property = properties[i], value = source[property];
|
||||
if (ancestor && Object.isFunction(value) &&
|
||||
value.argumentNames().first() == "$super") {
|
||||
var method = value, value = Object.extend((function(m) {
|
||||
var method = value;
|
||||
value = (function(m) {
|
||||
return function() { return ancestor[m].apply(this, arguments) };
|
||||
})(property).wrap(method), {
|
||||
valueOf: function() { return method },
|
||||
toString: function() { return method.toString() }
|
||||
});
|
||||
})(property).wrap(method);
|
||||
|
||||
value.valueOf = method.valueOf.bind(method);
|
||||
value.toString = method.toString.bind(method);
|
||||
}
|
||||
this.prototype[property] = value;
|
||||
}
|
||||
|
|
|
@ -498,6 +498,17 @@ new Test.Unit.Runner({
|
|||
valueOf: function() { return "valueOf" }
|
||||
});
|
||||
|
||||
var Parent = Class.create({
|
||||
m1: function(){ return 'm1' },
|
||||
m2: function(){ return 'm2' }
|
||||
});
|
||||
var Child = Class.create(Parent, {
|
||||
m1: function($super) { return 'm1 child' },
|
||||
m2: function($super) { return 'm2 child' }
|
||||
});
|
||||
|
||||
this.assert(new Child().m1.toString().indexOf('m1 child') > -1);
|
||||
|
||||
this.assertEqual("toString", new Foo().toString());
|
||||
this.assertEqual("valueOf", new Foo().valueOf());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue