#276 √ invalid
John-David Dalton

Correction in the optimization of Function#bindAsEventListener

Reported by John-David Dalton | August 11th, 2008 @ 07:00 PM | in 1.6.0.4

Tobie has pointed out that the optimization of bindAsEventListener may not be needed and/or can at least be further optimized


  bindAsEventListener: function() {
    var __method = this, args = $A(arguments), object = args.shift();

    // Avoid using Array#concat when only the context argument is given.
    if (args.length) {
      return function(event) {
        return __method.apply(object, [event || window.event].concat(args));
      };
    }
    return function(event) {
      /* old code
      return __method.apply(object, [event || window.event]);
      */
      return __method.call(object, event || window.event); //<- better because it doesn't create an array each time and uses call for a single argument
    };
  },

Comments and changes to this ticket

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The Prototype JavaScript library.

Shared Ticket Bins