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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:16:52+00:00 2026-06-14T08:16:52+00:00

exports.list = function(callback){ var result = model.find({}, function(err, objects){ callback(null, objects) }); return result;

  • 0
exports.list = function(callback){

  var result = model.find({}, function(err, objects){
    callback(null, objects)
  });
  return result;
}

Q: Why is the above code a closure? Is it because the function parameter calls the function callback which is nested in it?

Q: does this cause an infinite loop, since the function is calling itself through its parameter?

Q: will the above function work if callback wasn’t defined anywhere?

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

    Q: Why is the above code a closure? Is it because the function parameter calls the function callback which is nested in it?

    A: As Mike explained, once an outside var is used inside a function, you create a closure.

    Q: does this cause an infinite loop

    A: I assume function(err, objects) will fire only once for the model, so no it won’t. You would create an infinite loop if you call callee (or self)

    Q: will the above function work if callback wasn’t defined anywhere?

    A: you will get an error ReferenceError: callback is not defined

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

Sidebar

Related Questions

I got this two functions exports.list = function (req, res){ Material.find(function(err, materials) { res.render('materials/list',
Here's the code: exports.index_post = function(req, res) { var nicks = []; if (req.body.nick)
Is there a way to output e.g. 2 objects without using list() ? my.fun=function(vector,
I find that exports.index = (req, res) -> res.render index, title: Hello compiles to
I have been analysing Ntdll file system functions from the total ntdll function list.
This is the code of my export_to_excel helper: function export_to_excel($query, $filename='exceloutput') { $headers =
From this post I got a script that exports a list as separate worksheets
I would like to dynamically get a list of either function names (as strings)
I'm busy following a tutorial where the author uses DUMPBIN to list exports, and
I am working on developing and optimizing a linear model using the lm() function

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.