[Webkit-unassigned] [Bug 26382] [ES5] Implement Function.prototype.bind

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sat Apr 24 19:31:07 PDT 2010


https://bugs.webkit.org/show_bug.cgi?id=26382





--- Comment #6 from kangax <kangax at gmail.com>  2010-04-24 19:31:05 PST ---
The fastest implementation of `bind` I was able to come up with back in the
days was the one with load-time + run-time forking (to avoid unnecessary
arguments concatenation). Does native `bind` perform better than this
"optimized" version?

Function.prototype.bind = (function(){

  var _slice = Array.prototype.slice;

  return function(context) {
    var fn = this,
        args = _slice.call(arguments, 1);

    if (args.length) { 
      return function() {
        return arguments.length
          ? fn.apply(context, args.concat(_slice.call(arguments)))
          : fn.apply(context, args);
      }
    } 
    return function() {
      return arguments.length
        ? fn.apply(context, arguments)
        : fn.call(context);
    }; 
  }
})();


There are also some tests in this thread:
https://prototype.lighthouseapp.com/projects/8886/tickets/215-optimize-bind-bindaseventlistener

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list