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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:16:43+00:00 2026-06-11T20:16:43+00:00

This may be a javascript 101 or Backbone 100 questions. But I feel comfortable

  • 0

This may be a javascript 101 or Backbone 100 questions. But I feel comfortable in asking this beginning question and not being made fun of here 🙂

The following code snippet is from Code School’s Anatomy of Backbone JS course:

render: function(){ 
    this.collection.forEach(this.addOne, this);
} 

addOne: function(todoItem){
    var todoView = new TodoView({model: todoItem}); 
    this.$el.append(todoView.render().el);

}

The addOne function is being called from the render function. addOne function definition shows that one parameter “todoItem” is being passed to it. But if you look at the call to addOne from render, it does not show an argument/parameter being passed to it. How is it possible that the code works correctly?

Thanks in advance for your time.

Bharat

  • 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-11T20:16:44+00:00Added an answer on June 11, 2026 at 8:16 pm

    The first argument of the forEach function is a callback function, and the forEach function calls that function, handing in each element of the array as a parameter.

    More visually, your call to forEach would lead to:

    this.collection.forEach(this.addOne, this) -> 
               |this.addOne(this.collection[0], 0, this.collection)
               |this.addOne(this.collection[1], 1, this.collection)
               |this.addOne(this.collection[2], 2, this.collection)
               |this.addOne(this.collection[3], 3, this.collection)
               |this.addOne(this.collection[4], 4, this.collection)
               |...
               |this.addOne(this.collection[n], n, this.collection)
    

    .. where n represents the last index of the array this.collection.

    The function addOne will ignore the second and third parameters because addOne only specified one parameter. Also, this from addOne will be set to the this variable from render.

    More details are available from the Mozilla Developer Network and MSDN.

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

Sidebar

Related Questions

This may be a silly question, but why are function arguments in JavaScript not
This may or may not be a programming question, but one or two users
This may be a newbie question. I've used javascript for years but have only
This may or may not be a very trivial question, but then again, I'm
This may be a general javascript or jQuery question- I'm using backbone.js and I'd
This may be a fairly simple question but it's just not working for me
Unfortunately, this may not be a valid Code-Golf question as it is likely Javascript
This may be a stupid question but I have a code with the following
This may be a simple question but I can;t find the answer anywhere. Here
This may sound like a very generic question but here it goes. I have

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.