#276 ✓ invalid
John-David Dalton

Correction in the optimization of Function#bindAsEventListener

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

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 Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

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

Attachments

Tags

Referenced by

Pages