News for hackers. Stuff that matters.
Re:Ask HN: What is your favorite Javascript code snippet? by jashkenas on Tuesday June 29, 2010 @10:39PM (#1473688)
I'm partial to keeping a "bind" function handy. (Function#bind will be in ECMAScript 5, but it's not quite here yet). It's crucial for keeping your sanity when trying to use "this" with callbacks, Ajax, or async.

    var bind = function(func, context) {
      var slice = Array.prototype.slice;
      var args  = slice.call(args, 2);
      return function() {
        return func.apply(context || {}, args.concat(slice.call(arguments)));
      };
    };

There are no comments on this comment yet.