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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:13:18+00:00 2026-05-26T11:13:18+00:00

I have a custom function and I want to add a callback function to

  • 0

I have a custom function and I want to add a callback function to it, i looked through the other questions but I couldn’t really find the answer for my problem. So basically it looks like this:

function myfunction() {
 // something 
}

And I have a different function which I want to trigger as a callback, eventually i want to call myfunction like this:

myfunction(callback());

So can anyone please tell my the 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-05-26T11:13:19+00:00Added an answer on May 26, 2026 at 11:13 am

    You would call it like this (passing the callback function as an argument):

     myfunction(myCallbackFn);
    

    Notice that there are no parentheses after the function name when passing a reference to the function as an argument. This does not invoke the function, but just passes a reference to it which can then be called later from within your custom function.

    You would define your function and then call the callback function in it like this:

    function myfunction(cb) {
        cb(arg1, arg2);
    }
    

    Note, there are multiple methods of actually calling the callback function from within your custom function. If you just need to call it normally and don’t care about the this argument, you can just use:

    cb();
    

    If you want to set the this argument to something, you can use this:

    cb.call(thisArg, arg1, arg2);
    

    If you want to pass along your current arguments or pass an array of arguments and set the this argument, you would use this:

    cb.apply(thisArg, argArray);
    

    References on .call() and .apply().


    Your current code has a javascript error in this area:

    test(rand_gyumolcs, link, callback){
        callback();
    }; 
    

    This is not legal javascript. I don’t know what you’re trying to do, but this looks like half of a function declaration and half of a function call. If you just want to call the test function, you would just use this:

    test(rand_gyumolcs, link, callback);
    

    Inside of test, if you want the callback function to be called after the animation is complete, then you would have to hook the completion function of the animation and call the callback then.

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

Sidebar

Related Questions

I have a custom validation function in JavaScript in a user control on a
i have custom cell with 2 buttons(the function of these buttons is just to
I have a custom UITableViewCell. In its function - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier, I need
I have a load of php templates which uses a custom translate function __,
I have a custom control that has the following prototype. Type.registerNamespace('Demo'); Demo.CustomTextBox = function(element)
I have a function which takes a custom struct as the argument. how can
I have used sendinput() function and windows keyboard hooks to develop a custom keyboard
I have custom errors configured in my web.config, but IIS 6.0 is returning the
I have custom classes that I currently instantiate within App.xaml as resources. I want
I have a custom class library that performs validation. I want to open up

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.