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

  • Home
  • SEARCH
  • 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 7170703
In Process

The Archive Base Latest Questions

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

What is options in Backbone.js that I see all over the official source code

  • 0

What is “options” in Backbone.js that I see all over the official source code and also used in a tutorial blog by Thomas Davis with sample code here:

Friends = Backbone.Collection.extend({
     initialize: function (models, options) {
                   this.bind("add", options.view.addFriendLi); 
                 }
});

I don’t see any other tutorials using it, and even the doc mentioning it. It does, but in a context kind of format ([options]), not in a hard-coded “options”: options.view.addFriendLi

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

    options, conventionally, is a javascript object of key/value pairs that provide data/context/arguments/configuration to a method call. Think of it like named arguments, as opposed to ordered arguments.

    For example:

    var makePerson = function(name, options) {
      var person = {};
      person.name = name;
      person.age  = options.age;
      return person;
    };
    
    var me = makePerson('Alex', {age:30}); // In 3 days... scary :(
    

    How the function being called uses this object, is up to that function.

    The documentation for backbone for Collection.initialize() does not seem to list what keys on the options object are used or expected, which is unfortunate. So without looking at the source, there is no way to tell. But your example does seem to indicate a view key is expected. So you might call it like this:

    var friendsCollection = new Friends(userModels, {view: someBackboneView});
    

    This is simply a convention many libraries tend to use, and there is nothing special about it. But usually many keys in an object that is passed to a function call is better than a funciton that you call with many arguments, because each value has a label which makes it clear what each value is for.


    Looking a bit further, now here: http://documentcloud.github.com/backbone/docs/backbone.html#section-53

    It looks like Collection.initialize() only accepts a single key in it’s options: comparator. Here you can define a function used to sort the models in the collection:
    http://documentcloud.github.com/backbone/#Collection-comparator

    Working that into your example, you would call that like this:

    var friendsCollection = new Friends(userModels, {
      view: someBackboneView,
      comparator: function(friend) {
        return friend.get('age');
      }
    });
    
    • 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 the following backbone.js code and i have a problem in that event
What options are there for installing Django such that multiple users (each with an
I'm building an app using Brunch and Backbone.js that is to include nested menus.
I have noticed that when multiple attributes of a Backbone model are set like
I am using underscore.js's templating capabilities from backbone.js, I have the following template that
I have a working coffeescript/backbone idiom that looks like this: SidebarWidgets = ((() ->
I've built a Backbone-powered library that allows a user to add/remove items, much like
Hi all I am creating my first Backbone.js app. It is basically a collection
I have several views that have common code I'd like to abstract into a

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.