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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:39:37+00:00 2026-06-04T17:39:37+00:00

In everything I’ve read thus far, callback functions are passed as arguments into other

  • 0

In everything I’ve read thus far, callback functions are passed as arguments into other functions:

function mycallback(){
    //dosomething
}

function mainfunc(mycallback){
    //do something else
    mycallback();
}

mainfunc(mycallback);

Which works as you would expect, great. My question is if the passing of the callback function as an argument into the mainfunc is requried? It seems if you omit this:

function mycallback(){
    //dosomething
}

function mainfunc(){
    //do something else
    mycallback();
}

mainfunc();

it works fine, and is identical to the first example. But I don’t see people using callbacks in this way. Is there a reason? What am I missing?

  • 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-04T17:39:38+00:00Added an answer on June 4, 2026 at 5:39 pm

    You second approach works fine if you want a single function to handle all callbacks.

    Often when you call a method that uses a callback, you want it to different things in the callback depending on when you call it and from where. Instead of handling all different situations in a single callback function (which then has to be aware of which situation it is), you can simply use one callback function for each specific situation.

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

Sidebar

Related Questions

Everything I have read so far, it seems as though you copy the DB
Everything worked fine until sequentce with the only element was passed to this function.
Everything worked fine until sequentce with the only element was passed to this function.
Everything i read tells me this should work page 1 is <?php $state =
Everything i've read about objective-c memory management makes it sound incredible easy. To paraphrase
Everything I read online talks about Info.plist. XCode made me a [name of the
Everything I have read says that when making a managed stored procedure, to right
Everything I read about better PHP coding practices keeps saying don't use require_once because
Everything I've read seems to imply that building a cross-compiler is significantly harder than
Everything I read about cookies says that setting the expiry time of a cookie

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.