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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:42:09+00:00 2026-06-06T08:42:09+00:00

First of all, I did some search and no answer on stackoverflow/google provided me

  • 0

First of all, I did some search and no answer on stackoverflow/google provided me the thing I wanted.

Here’s a snippet of my code:

//in the view
this.collection.on("add",triggerthis)
this.collection.add(predefinedModel)
triggerthis: function(a, b, c, d){
    //etc.
}

Basically, I want to be able to pass an argument on add and receive the argument in triggerthis. Is this possible?

Thanks in advance.

  • 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-06T08:42:14+00:00Added an answer on June 6, 2026 at 8:42 am

    You can’t do this the way you want without using undocumented features.

    If we have a look at Collection#add, we’ll see this:

    add: function(models, options) {
      //...
      for (i = 0, l = add.length; i < l; i++) {
        (model = add[i]).trigger('add', model, this, options);
      }
      //...
    }
    

    Note the fourth argument to trigger. And if we look at the documented interface for trigger:

    trigger object.trigger(event, [*args])

    Trigger callbacks for the given event, or space-delimited list of events. Subsequent arguments to trigger will be passed along to the event callbacks.

    So the add will call the listeners as f(model, collection, options) where options is the same options what you passed to Collection#add. The result is that if you do this:

    this.collection.add(predefinedModel, { undocumented: 'arguments' })
    

    then you could do this in your callback:

    triggerthis: function(model, collection, options) {
        console.log(options.undocumented);
    }
    

    Demo: http://jsfiddle.net/ambiguous/bqWwQ/

    You could of course tunnel a whole array or object through options this way.

    The third argument for "add" events isn’t documented (at least not that I can find), the closest thing to documentation for this is a note in the 0.3.3 Changelog entry:

    The ubiquitous options argument is now passed as the final argument to all "change" events.

    I wouldn’t recommend this approach but it is there if you need it; you will of course need to cover this in your test suite and you’ll need to make sure you don’t use any keys in options that Backbone will be using.


    A safer approach would be to attach some extra properties to the model:

    model.baggage = { some: 'extra stuff };
    

    and then peel that off in the callback:

    triggerthis: function(model, collection) {
        var baggage = model.baggage;
        delete model.baggage;
        //...
    }
    

    Demo: http://jsfiddle.net/ambiguous/M3UaH/

    You could also use different callbacks for different purposes or pass your extra parameters as full blown model attributes.

    There’s also _.bind:

    this.collection.on("add", _.bind(function(collection, model, extra) { ... }, context, collection, model, 'whatever you want'));
    

    but that will bind arguments from left to right so you’ll have to specify all the arguments that your callback will need.

    Demo: http://jsfiddle.net/ambiguous/jUpJz/

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

Sidebar

Related Questions

First of all, I did some searching for an answer to this question...but I
First of all, I did a search on this and was able to find
First of all I did gave a look at this one. But I didn't
First of all, I've searched thoroughly online and here, without finding a clear solution
I'm new to Stack and this is my first question, but I did search
First of all, I want to be clear: I did manage to get Internet
First of all I would like to tell you all that I did a
first of all, sorry if that question is dumb but I´m a total newbie
First of all, what's the difference between: www.domain.com and domain.com Should I pay attention
First of all, I'm really new to the MVC Asp.Net ideology. I would like

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.