Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. // 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
  6. // internal IsCallable function
  7. throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
  8. }
  9.  
  10. var aArgs = Array.prototype.slice.call(arguments, 1),
  11. fToBind = this,
  12. fNOP = function() {},
  13. fBound = function() {
  14. return fToBind.apply(this instanceof fNOP
  15. ? this
  16. : oThis,
  17. aArgs.concat(Array.prototype.slice.call(arguments)));
  18. };
  19.  
  20. fNOP.prototype = this.prototype;
  21. fBound.prototype = new fNOP();
  22.  
  23. return fBound;
  24. };
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement