bind.js 675 B

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