Skip to content

Commit 2e82af2

Browse files
Avoid using Function#bind when copying a method's toString and valueOf methods to its wrapped version in class creation.
The previous commit fixes the issue in our own polyfill that was causing this error, but we're changing this anyway because people might be relying on the MDC polyfill in the wild.
1 parent 6e96542 commit 2e82af2

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/prototype/lang/class.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,22 @@ var Class = (function() {
167167
value = (function(m) {
168168
return function() { return ancestor[m].apply(this, arguments); };
169169
})(property).wrap(method);
170-
171-
value.valueOf = method.valueOf.bind(method);
172-
value.toString = method.toString.bind(method);
170+
171+
// We used to use `bind` to ensure that `toString` and `valueOf`
172+
// methods were called in the proper context, but now that we're
173+
// relying on native bind and/or an existing polyfill, we can't rely
174+
// on the nuanced behavior of whatever `bind` implementation is on
175+
// the page.
176+
//
177+
// MDC's polyfill, for instance, doesn't like binding methods that
178+
// haven't got a `prototype` property defined.
179+
value.valueOf = (function(method) {
180+
return function() { return method.valueOf.call(method); };
181+
})(method);
182+
183+
value.toString = (function(method) {
184+
return function() { return method.toString.call(method); };
185+
})(method);
173186
}
174187
this.prototype[property] = value;
175188
}

0 commit comments

Comments
 (0)