Skip to content

Commit

Permalink
Avoid using Function#bind when copying a method's toString and `v…
Browse files Browse the repository at this point in the history
…alueOf` 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.
  • Loading branch information
savetheclocktower committed May 23, 2012
1 parent 6e96542 commit 2e82af2
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/prototype/lang/class.js
Expand Up @@ -167,9 +167,22 @@ var Class = (function() {
value = (function(m) {
return function() { return ancestor[m].apply(this, arguments); };
})(property).wrap(method);

value.valueOf = method.valueOf.bind(method);
value.toString = method.toString.bind(method);

// We used to use `bind` to ensure that `toString` and `valueOf`
// methods were called in the proper context, but now that we're
// relying on native bind and/or an existing polyfill, we can't rely
// on the nuanced behavior of whatever `bind` implementation is on
// the page.
//
// MDC's polyfill, for instance, doesn't like binding methods that
// haven't got a `prototype` property defined.
value.valueOf = (function(method) {
return function() { return method.valueOf.call(method); };
})(method);

value.toString = (function(method) {
return function() { return method.toString.call(method); };
})(method);
}
this.prototype[property] = value;
}
Expand Down

0 comments on commit 2e82af2

Please sign in to comment.