Commit ee7cae00 ee7cae00a9844f9768a756ac6fe8b002035bf580 by Nicolas Perriault

fixes #631 - better .bind() polyfill

1 parent b7f76a21
......@@ -44,12 +44,24 @@ if (!('phantom' in this)) {
// Common polyfills
if (typeof Function.prototype.bind !== "function") {
Function.prototype.bind = function(scope) {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Compatibility
Function.prototype.bind = function (oThis) {
"use strict";
var _function = this;
return function() {
return _function.apply(scope, arguments);
/* jshint -W055 */
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function() {},
fBound = function() {
return fToBind.apply(this instanceof fNOP && oThis ? this : oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
......