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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:24:45+00:00 2026-05-24T22:24:45+00:00

here is my code db.query(str, arr, function selectCb(error, results, fields) { if (error) {

  • 0

here is my code

db.query(str, arr, function selectCb(error, results, fields) {
            if (error) {
                return proceed(false, {errno:'010',message:error.message}, request);
            }
            var q = async.queue(function (results, callback) {
                // add the gib infor
                if (results.refertype=='G') {
                    var input={};
                    input.fields="*";
                    input.gibname=results.refername;
                    gib.getgibinternal(input, makeCallback(i));
                    function makeCallback(index) {
                        return function(gresult) {
                            results.gib=gresult.data[0];
                            callback(results);
                        }
                    }
                    // add the user info        
                } else if(results.refertype=='U') {
                    var input={};
                    input.username=results.refername;
                    input.fields="*";
                    user.getuserinternal(input, makeCallbackuser(i));
                    function makeCallbackuser(index) {
                        return function(gresult) {
                            results.user=gresult.data[0];
                            callback(results);
                        }
                    }
                } 

            }, results.length);
            // assign a callback
            q.drain = function() {
                return proceed(true, self.results, self.request);
            }
            self.results=results;

            for (var i=0; i<results.length; i++) {
                // the first console
                console.log(results[i]);
                // add some items to the queue
                q.push(results[i], function (results) {
                     results[i]=results;
                     self.results[i]=results;
                                    //the second console.
                    console.log(results);
                });
            }
            if (results.length==0) {
                return proceed(true, results, request);
            }  
        });

The out put of above code is :

// the first console
{ cardid: 30,
  cardtype: 'I',
  status: 'A',
  refername: 'admin',
  refertype: 'U' }
// the second console 
{ '1': [Circular],
  cardid: 30,
  cardtype: 'I',
  status: 'A',
  refername: 'admin',
  refertype: 'U',
  user:
   { name: 'admin',
     username: 'admin',
     deleted: 'N' } }

how this '1': [Circular], get added .?

  • 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-05-24T22:24:46+00:00Added an answer on May 24, 2026 at 10:24 pm

    This bit:

    q.push(results[i], function (results) {
    

    is the same as this (with some renaming to make it easier to track the scope):

    q.push(self.results[i], function(r) {
        r[i] = r; // <------------------- Look at me!
        self.results[i] = r;
        //the second console.
        console.log(r);
    });
    

    The self.results[i] change just comes from the self.results=results; right above your for loop. The interesting part is this:

        r[i] = r;
    

    If i is 1 you will have added a property named 1 to r whose value is r itself, hence the [Circular]. I would hazard a guess that results.length is 2 and that your function is acting as a closure over i and ending up with using the last value that i had and that’s why you get the '1' rather than a '0' property.

    I see three main Things that could be causing you trouble:

    • The classic closure problem with i.
    • Too many things were called results so it was easy to lose track of which one you were working with.
    • The circular reference: r[i] = r;.

    Another possible source of confusion is that results and self.results are the same object but that might be okay.

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

Sidebar

Related Questions

Ok the error is showing up somewhere in this here code if($error==false) { $query
I try to execute mysql query passing variable. Here is my code char str[100]
Right, starting to go crazy here. I have the following code: var query =
Here is the pseudo-code for my inline query in my code: select columnOne from
here is the code: if (($handle = fopen($source_file, r)) !== FALSE) { $columns =
first function is this $output_csv = fopen( Poems.csv, w ); ..code here $poem_text =
Here's the code: mysql_query(DELETE . $_GET['id'] . FROM forum_favorites WHERE thread_id=' . $_GET['id'] .
Here is code from MSDN . I don't understand why the work isn't just
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),
enter code here I have a table on SQL server 2005 with bigint primary

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.