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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:27:30+00:00 2026-06-02T03:27:30+00:00

I was reading some of Facebook’s JavaScript, and came across a curious function that

  • 0

I was reading some of Facebook’s JavaScript, and came across a curious function that I couldn’t figure out the purpose of:

function bagof(a) {
    return function () {
        return a;
    };
}

As far as I can tell:

  • bagof is a function that accepts the parameter a.
  • bagof immediately returns an anonymous function.
  • The returned function then returns the original parameter a.

I would assume that the usage of bagof would be something like this:

newFunction = bagof("This is the data");
​console.log( newFunction() );​ //Logs "This is the data"​​​​​​​​​​​​

What’s the point? Why not directly use or store whatever variable or function that was passed into a?

The source file looks like it contains many utility functions for the application.

  • 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-02T03:27:32+00:00Added an answer on June 2, 2026 at 3:27 am

    The bagof() method can be used as a factory creating constant functions (functions always returning the same value).

    Even if you use in such a context:

    var randomFun = bagof(Math.random());
    

    Invocation of randomFun() will always return the same value because Math.random() is evaluated only once (eagerly). I guess it is utility method used when some API requires a method and we simply want to pass constant value. Instead of:

    giveMeCallback(function() {return 42})
    

    you can simply say:

    giveMeCallback(bagof(42))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading some Python (PyQt) code, I came across as follows. @pyqtSignature(QString) def on_findLineEdit_textEdited(self, text):
from reading some links on SO, came across 'playframework' to build java web app.
I was reading some Java recently and came across something (an idiom?) new to
I was reading the facebook API references. http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ My client wants some sort of
After reading some posts like this one: Choose File Dialog It appears that Android
Been reading here for quite a while now.. But cant seem to figure out
I remember reading some time ago that there were cpu cards for systems to
I'm reading some data that has already been converted to html style υ code.
After reading some information I thought this should work. The JS function is called
Facebook scraper throws some weird stuff when reading the contents of my page... Page

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.