Skip to content

Commit 8e0fb68

Browse files
author
Eric Wendelin
committed
Revert "Fix Function.bind polyfill."
This reverts commit 63e5a22.
1 parent 4c9683d commit 8e0fb68

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

polyfills.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
// ES5 Polyfills
22
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
33
if (!Function.prototype.bind) {
4-
Function.prototype.bind = function bind(obj) {
5-
var args = slice.call(arguments, 1);
6-
var self = this;
7-
var F = function() {};
8-
var bounded = function() {
9-
return self.apply(
10-
this instanceof F ? this : (obj || {}),
11-
args.concat(slice.call(arguments))
12-
);
4+
Function.prototype.bind = function (oThis) {
5+
if (typeof this !== 'function') {
6+
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
7+
}
8+
9+
var aArgs = Array.prototype.slice.call(arguments, 1);
10+
var fToBind = this;
11+
var NoOp = function () {
12+
};
13+
var fBound = function () {
14+
return fToBind.apply(this instanceof NoOp && oThis ? this : oThis,
15+
aArgs.concat(Array.prototype.slice.call(arguments)));
1316
};
14-
F.prototype = this.prototype || {};
15-
bounded.prototype = new F();
16-
return bounded;
17+
18+
NoOp.prototype = this.prototype;
19+
fBound.prototype = new NoOp();
20+
21+
return fBound;
1722
};
1823
}
1924

25+
2026
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
2127
if (!Array.prototype.map) {
2228
Array.prototype.map = function(callback, thisArg) {

0 commit comments

Comments
 (0)