Guest User

Untitled

a guest
Oct 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. if (!Function.prototype.bind) {
  2.  
  3. Function.prototype.bind = function (oThis) {
  4.  
  5. if (typeof this !== "function") {
  6.  
  7. // closest thing possible to the ECMAScript 5 internal IsCallable function
  8.  
  9. throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
  10.  
  11. }
  12.  
  13. var aArgs = Array.prototype.slice.call(arguments, 1),
  14.  
  15. fToBind = this,
  16.  
  17. fNOP = function () {},
  18.  
  19. fBound = function () {
  20.  
  21. return fToBind.apply(this instanceof fNOP
  22.  
  23. ? this
  24.  
  25. : oThis || window,
  26.  
  27. aArgs.concat(Array.prototype.slice.call(arguments)));
  28.  
  29. };
  30.  
  31. fNOP.prototype = this.prototype;
  32.  
  33. fBound.prototype = new fNOP();
  34.  
  35. return fBound;
  36.  
  37. };
  38.  
  39. }
Add Comment
Please, Sign In to add comment