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 8050565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:06:56+00:00 2026-06-05T07:06:56+00:00

I can attach handlers to Backbone Views like: var TodoView = Backbone.View.extend({ events: {

  • 0

I can attach handlers to Backbone Views like:

var TodoView = Backbone.View.extend({
    events: {
        "xxx": "eventHandler1"
        "yyy": "eventHandler2"
    }
});

But what if I want to attach more than 1 handler to the same event?

var TodoView = Backbone.View.extend({
    events: {
        "xxx": "eventHandler1"
        "yyy": "eventHandler2"
        "xxx": "eventHandler3" // this isn't valid ... at least in CoffeeScript
    }
});

I could create a custom handler like

function compositeXXX() { eventHandler1(); eventHandler2 }

But this doesn’t seem ideal …

  • 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-06-05T07:06:57+00:00Added an answer on June 5, 2026 at 7:06 am

    This:

    events: {
        "xxx": "eventHandler1",
        "yyy": "eventHandler2",
        "xxx": "eventHandler3"
    }
    

    won’t work because events is an object literal and you can have at most one (key,value) pair in an object. That would probably be the same as saying:

    events: {
        "xxx": "eventHandler3",
        "yyy": "eventHandler2"
    }
    

    This CoffeeScript:

    events:
        "xxx": "eventHandler1"
        "yyy": "eventHandler2"
        "xxx": "eventHandler3"
    

    is functionally identical to the JavaScript version and won’t work for the same reason.

    Andy Ray’s idea of using

    'event selector': 'callback1 callback2'`
    

    won’t work either as Backbone won’t understand that it should split the value on whitespace; similarly, this:

    'event selector': [ 'callback1', 'callback2' ]
    

    won’t work because Backbone doesn’t know what to do with an array in this context.

    Views bind their events through delegateEvents and that looks like this:

    delegateEvents: function(events) {
      // Some preamble that doesn't concern us here...
      for (var key in events) {
        var method = events[key];
        if (!_.isFunction(method)) method = this[events[key]];
        if (!method) throw new Error('Method "' + events[key] + '" does not exist');
        // And some binding details that are of no concern either...
      }
    }
    

    So method starts out as the value for 'event selector'. If it is a function from something like:

    'event selector': function() { ... }
    

    then it is used as-is, otherwise it is converted to a property of this:

    method = this[events[key]]; // i.e. method = this[method]
    

    If one were bold, one could adjust delegateEvents to understand an array or whitespace delimited string:

    // Untested code.
    var methods = [ ];
    if (_.isArray(method))
      methods = method;
    else if (_.isFunction(method))
      methods = [ method ];
    else
      methods = method.split(/\s+/);
    for (var i = 0; i < methods.length; ++i) {
      method = methods[i];
      if (!_.isFunction(method))
        method = this[method];
      // And the rest of the binding stuff as it is now with a possible adjustment
      // to the "method does not exist" exception message...
    }
    

    A fairly simple patch like that would allow you to use a whitespace delimited list of handlers:

    'event selector': 'callback1 callback2'
    

    or an array of handlers:

    'event selector': [ 'callback1', 'callback2' ]
    

    or even a mixed array of method names and functions:

    'event selector': [ 'callback_name1', function() { ... }, 'callback_name2' ]
    

    If you don’t want to patch your Backbone or forward such a patch to the Backbone maintainers then you could go with your original “manual dispatching” idea:

    'event selector': 'dispatcher'
    //...
    dispatcher: function(ev) {
        this.handler1(ev);
        this.handler2(ev);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I attach any event handlers to HTML hidden input fields? Basically I want
There are two parts to my question - Firstly we can attach event handlers
I known that with subversion you can attach arbitrary properties to each files. In
I read that the new delegate method can attach more than one event to
With the [attribute] notation I can attach custom attributes to class instance methods. But
Does jquery/javascript have any event model that you can attach to your objects? Basically
I've created a WPF application with a frame inside. I can attach some other
Can an attacker attach a debugger to my app after installing it to the
I can see how to attach an event to an object that has no
How can I create an NSPopUpButton programmatically and attach the menu items to it?

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.