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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:42:49+00:00 2026-05-28T07:42:49+00:00

I have this JS code: Download.prototype.insert = function(stocks, exchange, cb){ var self = this

  • 0

I have this JS code:

Download.prototype.insert = function(stocks, exchange, cb){
    var self  = this
      , count = stocks.length      

    stocks.forEach(function(stock){     
        save(stock, done)
    })

    function save(stock, cb){
        self.mysql.query("my query", [exchange.id, stock.Symbol], function(err, rows){
            if (rows && rows.length > 0) 
                self.mysql.query("my query", [rows[0].id, stock.DateTime, stock.Close], cb)
            else cb()   
        })      
    }

    function done(){                
        count--
        if (count === 0) return cb()        
    }
}

as you can see I pass a callback to the save() function, I would like to know if i can separate the queries to avoid using of function(err, rows){ .... }

the problem is that function wait two parameters err and rows, so How can I also pass a custom third parameter (the cb() function) ?

Thanks

  • 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-28T07:42:49+00:00Added an answer on May 28, 2026 at 7:42 am

    I hope I understood your question right ^^

    To wrap your callback parameter, you can create a function that returns an anonymous function (the actual callback). The cb parameter gets wrapped into the context of the anonymous function:

    function queryDetails(cb){
      return (
        function(err, rows){
          if(rows && rows.length < 0){
            //mysql.query ...
          }else{
            cb()
          }
        })
     };
     mysql.query("query", ...., queryDetails(doneCallback));
    

    Have fun!

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

Sidebar

Related Questions

I have this code in PHP: header(Content-Type: application/vnd.ms-excel); header(Content-Type: application/download); header(Content-Length: .filesize($path.$filename)); header(Content-disposition: attachment;
I have this code in jQuery, that I want to reimplement with the prototype
I have this code while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row
Hi I have this code to download images from the server and then to
I have this code: <object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='800' height='470' id='Gen5Core' align='middle'><param name='allowScriptAccess' value='always'/><param name='allowFullScreen'
I have this code NSString *tr = [self sendUrl:@http://google.com/]; But for some reason '
I have a few questions regarding android source code download, repo / git. This
I have this code: public static String Download(string address) { WebClient client = new
In my gsp view, I have this code : <g:each in=${fileResourceInstanceList} status=i var=fileResourceInstance> <tr
We have this code which serves a download: public class downloadRelease : IHttpHandler {

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.