View Single Post
Old 11-21-2012, 09:04 AM   PM User | #7
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Here's a shorter version of bind than the one I mentioned from the book - it gets rid of the unnecessary loops.

Code:
if (!Function.prototype.bind) {
   Function.prototype.bind = function(o) {
   var self, bndargs;
   self = this;
   bndargs = Array.prototype.slice.call(arguments);
   bndargs.shift();
   return function() {
      var args = bndargs.concat(Array.prototype.slice.call(arguments));
      return self.apply(o, args);
      };
   };
};
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote