Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6539853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:54:31+00:00 2026-05-25T10:54:31+00:00

Which pattern is best, and why? $myElements.delegate(selector, ‘event1 event2’, function () { if (event.type

  • 0

Which pattern is best, and why?

$myElements.delegate(selector, 'event1 event2', function () {
   if (event.type === 'event1') { /* Handle event 1 */ }
   if (event.type === 'event2') { /* Handle event 2 */ }
}

OR

$myElements
   .delegate(selector, 'event1', function () {
       /* Handle event 1 */
}
   .delegate(selector, 'event2', function () {
       /* Handle event 2 */
}

In other words, is it better to have one large unified handler, or many small separate handlers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:54:32+00:00Added an answer on May 25, 2026 at 10:54 am

    I am fairly sure that the second solution is to be preferred. From the jQuery source:

    // Handle multiple events separated by a space
    // jQuery(...).bind("mouseover mouseout", fn);
    types = types.split(" ");
    

    So there is the step of splitting a string and then running through a while loop for each event. In the first case the handler is called for every event and then your if statement is executed. In the second only the handler actually attached is being called.

    Besides, the second version is a lot easier to read as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the MVC design pattern, which class file (appdelegate, viewcontroller etc) is best suited
$('.s').keyup(function(e) { if (!/[A-Za-z0-9]/.test(String.fromCharCode(e.which))) { return false; } I wonder what is the best
Is there a design-pattern which is recognized as the best pattern to use when
I'm trying to find a design pattern or a best practice, or some other
I have an MVC-based site, which is using a Repository/Service pattern for data access.
Which of the following has the best performance? I have seen method two implemented
Which pattern could be used in web projects? I am developing a wiki project
I am trying to determine the best design pattern to use for a business
I am having a very hard time finding a standard pattern / best practice
What's the best pattern for making datasets threadsafe on write? The best I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.