2
0

bind.js 835 B

1234567891011121314151617181920212223242526
  1. // PhantomJS doesn't have fn.bind()
  2. // - WAT?
  3. if (!Function.prototype.bind) {
  4. Function.prototype.bind = function (oThis) {
  5. if (typeof this !== "function") {
  6. // closest thing possible to the ECMAScript 5 internal IsCallable function
  7. throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
  8. }
  9. var aArgs = Array.prototype.slice.call(arguments, 1),
  10. fToBind = this,
  11. fNOP = function () {},
  12. fBound = function () {
  13. return fToBind.apply(this instanceof fNOP && oThis
  14. ? this
  15. : oThis,
  16. aArgs.concat(Array.prototype.slice.call(arguments)));
  17. };
  18. fNOP.prototype = this.prototype;
  19. fBound.prototype = new fNOP();
  20. return fBound;
  21. };
  22. }