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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:29:37+00:00 2026-06-10T12:29:37+00:00

I like to write my callback functions in a private namespace and then call

  • 0

I like to write my callback functions in a private namespace and then call them by reference. eg

var myCallback = function() {

};

// ... somewhere else in the class.
SomeOtherObject.doSomething(myCallback);

This makes the code neater and more extendable. However when I need to pass any parameters to the callback from the original function it becomes messy and I have to enclose the callback reference in a closure. eg

var myCallback = function(a_var, another_var) {

};

// ... somewhere else in the class.
a_var = "something";
SomeOtherObject.doSomething(function(another_var) {
    myCallback(a_var, another_var);
};

This results in the callback requiring two function calls instead of one, creating overhead. It also means I have an undocumented anonymous function for the closure – or I document both functions. (It’s not so much the missing function definition which is annoying as the parameter definitions.) If the callback is small – as good functions are – then it makes it seem not worthwhile to put it the private scope.

What is the best way to do this?

  • 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-10T12:29:38+00:00Added an answer on June 10, 2026 at 12:29 pm

    Partial application implementations allow you to pass variables in this way.

    For example, using native ES5’s bind:

    SomeOtherObject.doSomething( myCallback.bind(null, a_var) );
    

    another_var will be passed to that function when called

    It’s not supported everywhere though, so you can grab the one from underscore and use that instead.

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

Sidebar

Related Questions

I would like to write a function that creates a plot of a set
I'd like to write an express middleware function that sets up a listener on
i would like to pass multiple parameters in my callback function and don't know
I'd like to write a small JavaScript (framework) that can chain functions with all
I am trying to write a generic type-bound procedure that takes different callback functions
If I write like this: ShellExecute(NULL, open, www.google.com, NULL, NULL, SW_SHOWNORMAL); Everything's okay and
I like to write a process in Worker role, to download (sync) batch of
I would like to write an abstract base class class func_double_double_t : public unary_function<double,
I'd like to write an app that monitors incoming SMS and notify me on
I'd like to write tests for a suite of Parsec parsers. Here's a simple

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.