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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:20:57+00:00 2026-06-09T04:20:57+00:00

Possible Duplicate: underscore.js _.each(list, iterator, [context]) what is context? So in the context of

  • 0

Possible Duplicate:
underscore.js _.each(list, iterator, [context]) what is context?

So in the context of this forEach function in underscore.js:

// The cornerstone, an `each` implementation, aka `forEach`.
// Handles objects with the built-in `forEach`, arrays, and raw objects.
// Delegates to **ECMAScript 5**'s native `forEach` if available.
var each = _.each = _.forEach = function(obj, iterator, context) {
  if (obj == null) return;
  if (nativeForEach && obj.forEach === nativeForEach) {
    obj.forEach(iterator, context);
  } else if (obj.length === +obj.length) {
    for (var i = 0, l = obj.length; i < l; i++) {
      if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return;
    }
  } else {
    for (var key in obj) {
      if (_.has(obj, key)) {
        if (iterator.call(context, obj[key], key, obj) === breaker) return;
      }
    }
  }
};

What is the parameter context and how is it used?

  • 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-09T04:20:59+00:00Added an answer on June 9, 2026 at 4:20 am

    Sets the this value (the calling context) of the iterator function that was passed.

    iterator.call(context, obj[i], i, obj);
          //         ^---right here
    

    JavaScript’s .call and .apply methods let you invoke a function with the this value of the function you’re calling set to the first argument you provide.

    So if I do…

    var obj = {foo:"bar"};
    func.call(obj);
    

    …the value of this inside func will be the {foo:"bar"} object.

    So if you provide that argument, underscore uses it as the first argument to .call when invoking the function you passed as seen above.

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

Sidebar

Related Questions

Possible Duplicate: C# foreach vs functional each This is a question about coding for
Possible Duplicate: Synthesized property and variable with underscore prefix: what does this mean? I've
Possible Duplicate: Underscore prefix on property name? What does this mean? @synthesize window=_window; I
Possible Duplicate: Synthesized property and variable with underscore prefix: what does this mean? The
Possible Duplicate: What does :_* (colon underscore star) do in Scala? I’m using the
Possible Duplicate: How does an underscore in front of a variable in a cocoa
Possible Duplicate: What does a type followed by _t (underscore-t) represent? While typing in
Possible Duplicate: What does a type followed by _t (underscore-t) represent? Does anyone knows
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:

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.