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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:11:13+00:00 2026-05-27T19:11:13+00:00

Just getting started with backbone.js, and one of the things I’ve noticed is that

  • 0

Just getting started with backbone.js, and one of the things I’ve noticed is that many of my models, collections and views share some very similar methods. I’d like to refactor them & call them from an extracted location (/lib?). I went searching for documentation and/or examples, and was surprised by how little I found (specifically, none). So, a few questions:

  • Is there a reason I’m overlooking as to why there are so few examples of backbone methods factored out into common libraries?
  • Is there a standard/agreed upon location in backbone projects for shared code?
  • Any backbone classes and/or common plugins to help store common methods?

Any ideas appreciated – thanks in advance.

(EDIT) Example added:

Take this code from a view. (Admittedly it’s too short be actually worth refactoring, but its simplicity makes it a concise example)

  destroy: () ->
    @model.destroy()
    @remove()
    return false

Suppose I wanted to refactor it into:

  destroy: () ->
    restful_destroy_method(this)

which then called:

 restful_destroy_method: (view) ->
    view.model.destroy()
    view.remove()
    return false

from a common library. Any reason why nobody else seems to do this?

  • 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-27T19:11:13+00:00Added an answer on May 27, 2026 at 7:11 pm

    It depends on the situation, and what your common code is.

    In the case of your example, what I might do would be to create a more specific View to extend from.

    Apologies for the straight JavaScript, I’m not as fluent in CoffeeScript to use it in an answer.

    DestroyableView = Backbone.View.extend({
        destroy: function () {
            this.model.destroy();
            this.remove();
            return false;
        }
    });
    

    Then, instead of creating new Backbone.View()s, I’d create new DestroyableView()s. DestroyableView could have other common functions, or you could create several different parent definitions and use _.extend() to apply them all to a single object.

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

Sidebar

Related Questions

Our team is just getting started with Mercurial. One of the first things we've
I'm just getting started in PowerShell and one of my sysadmins told me that
Just getting started with Obj-C and iOS programming. I have some code that loads
Just getting started with jQuery, and I've had some success so far. I've created
I'm just getting started with silverlight. Basically I have a silverlight user control that
I'm just getting started with cakePHP, and things aren't going so well so far.
I'm just getting started with Visual Studio (2010 Beta) and have some basic questions
Just getting started with Backbone.js. Simply including Backbone (either dev/production versions) causes the error:
Just getting started with OpenFrameworks and I'm trying to do something that should be
I'm just getting started with backbone, based on what I read, I couldn't tell

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.