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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:25:07+00:00 2026-05-28T15:25:07+00:00

I have a Backbone View for a general element that specific elements will be

  • 0

I have a Backbone View for a general element that specific elements will be inheriting from. I have event handling logic that needs to be applied to all elements, and event handling logic that is specific to child-type elements. I’m having trouble because a child View has its own callback for an event that is also handled by the parent View, and so when I try to use the events hash in both, either the child or parent callback is never called. Let me illustrate with some code:

var ElementView = Backbone.View.extend({
  events: {
    "mouseup": "upHandler",
    "mousedown": "downHandler",
    "mousemove": "moveHandler"
  },

  initialize: function() {
    // add events from child
    if (this.events)
      this.events = _.defaults(this.events, ElementView.prototype.events);

    this.delegateEvents(this.events);
  }
});

var StrokeView = ElementView.extend({
  events: {
    "mousemove": "strokeMoveHandler"
  }
});

How would I solve this in an extensible way, especially if I will later have another level of inheritance?

  • 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-28T15:25:08+00:00Added an answer on May 28, 2026 at 3:25 pm

    One way to handle this would be to use “namespaces” for events:

    var ElementView = Backbone.View.extend({
      events: {
        "mouseup.element": "upHandler",
        "mousedown.element": "downHandler",
        "mousemove.element": "moveHandler"
      },
    
      initialize: function() {
        // add events from child
        if (this.events)
          this.events = _.defaults(this.events, ElementView.prototype.events);
    
        this.delegateEvents(this.events);
      }
    });
    
    var StrokeView = ElementView.extend({
      events: {
        "mousemove.strokeview": "strokeMoveHandler"
      }
    });
    

    In fact, this approach is suggested in Backbone.js documentation.

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

Sidebar

Related Questions

I have the following class that extends Backbone.View, I want all my backbone views
I have a view that includes a table. var newsIndexView = Backbone.View.extend({ ... });
I have a Backbone View that uses iScroll to implement a slideshow. iScroll publishes
I have some Backbone.js code that bind a click event to a button, and
I have a generic subclass of Backbone.View which has a close event listener. var
I am new to Backbone.js. I have created a View for a button that
I have the following backbone.js code and i have a problem in that event
I have a backbone view that calls to a sub-view: lr.MapView = Backbone.View.extend({ el:
Have a LinqtoSql query that I now want to precompile. var unorderedc = from
As in the backbone-todolist example,I have a collection of elements. I made 2 views,

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.