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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:01:03+00:00 2026-06-02T01:01:03+00:00

What is more efficient, using events to communicate between nested Views, or keeping a

  • 0

What is more efficient, using events to communicate between nested Views, or keeping a reference around to call a method on. The following example shows two Views. The outer View responds to a click event, and could then use either an event, or method call to get the InnerView to respond appropriately.

InnerView = Backbone.View.extend({

    initialize: function() {
        this.model.bind('doSomethingEvent', this.doSomething);
    },

    doSomething: function() {
        // This could have been called from event/trigger
        // or from direction method invocation using reference.
    }
});


OuterView = Backbone.View.extend({

    events = {
        'click' : 'handleOutViewClick'
    },

    render: function() {

        // Create InnerView to render some model
        var innerView = new InnerView({model:this.model });

        $(this.el).append(innerView.render().el);

        // Could store a reference to the View?
        this.viewRef = innerView;
    },

    handleOutViewClick: function(e) {

        // Should this function use a reference to the InnerView instance:
        this.viewRef.doSomething();

        // Or should it trigger an event on this.model that 
        // the InnerView is bound to?
        this.someCollection.trigger('doSomethingEvent');
    }
});
  • 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-02T01:01:04+00:00Added an answer on June 2, 2026 at 1:01 am

    Probably a single method call is going to be more efficient than an event dispatch, which will involve at least 2 method calls. But I don’t think you need to be concerned about which is more “efficient” here technically. Unless this is happening many times a second, you can concern yourself only with what makes for cleaner, more correct code. I think the cleanest pattern depends on the details being communicated. Here’s my preference:

    1. If it is a natural fit for outerview to manipulate models and collections, and have innerview respond via the normal backbone model/collection events, that is the cleanest.

    2. If what’s happening isn’t really about the models, consider a “View Model” pattern where you model the interesting bits of state of the view as if it was a back end model, even though you have no intention of ever having that model interact with the server. Then bind your two views to events coming off the view model and have them coordinate by altering a common “view model” instance. This is a pattern I use for complicated views with lots of interdependent state not directly associated with the underlying models from the server.

    3. If what’s happening doesn’t really change the models/collections and is more of a view-specific thing, a direct method dispatch will be more straightforward but also more tightly coupled. It’s up to your judgement to decide when the loose coupling afforded by event dispatch merits the extra complexity and harder-to-follow control flow.

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

Sidebar

Related Questions

which of the following is more efficient? Using a get function on a token
Normally (ie. not concurrently), putAll() cannot be more efficient than using lot's of calls
Is it more efficient to use PHP's include_once or require_once instead of using a
Is there are more efficient way than the following for selecting the third parent?
What is more efficient -- having a IDbTransaction in the .net code or handling
Is it better (more efficient, faster, more secure, etc) to (A) cache data that
The DataReader is more efficient than a DataTable if you only need to show
What is the more efficient way to create a web video chat ? What
which is more efficient (when managing over 100K records): A. Mysql SELECT * FROM
Is there a more efficient (in terms of memory foot print) binding to datagrid

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.