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

  • Home
  • SEARCH
  • 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 586417
In Process

The Archive Base Latest Questions

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

All I need to do is to execute a callback function when my current

  • 0

All I need to do is to execute a callback function when my current function execution ends.

function LoadData() 
{
    alert('The data has been loaded');
    //Call my callback with parameters. For example,
    //callback(loadedData , currentObject);
}

A consumer for this function should be like this:

object.LoadData(success);

function success(loadedData , currentObject) 
{
  //Todo: some action here 
}

How do I implement 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-13T15:06:19+00:00Added an answer on May 13, 2026 at 3:06 pm

    Actually, your code will pretty much work as is, just declare your callback as an argument and you can call it directly using the argument name.

    The basics

    function doSomething(callback) {
        // ...
    
        // Call the callback
        callback('stuff', 'goes', 'here');
    }
    
    function foo(a, b, c) {
        // I'm the callback
        alert(a + " " + b + " " + c);
    }
    
    doSomething(foo);
    

    That will call doSomething, which will call foo, which will alert “stuff goes here”.

    Note that it’s very important to pass the function reference (foo), rather than calling the function and passing its result (foo()). In your question, you do it properly, but it’s just worth pointing out because it’s a common error.

    More advanced stuff

    Sometimes you want to call the callback so it sees a specific value for this. You can easily do that with the JavaScript call function:

    function Thing(name) {
        this.name = name;
    }
    Thing.prototype.doSomething = function(callback) {
        // Call our callback, but using our own instance as the context
        callback.call(this);
    }
    
    function foo() {
        alert(this.name);
    }
    
    var t = new Thing('Joe');
    t.doSomething(foo);  // Alerts "Joe" via `foo`
    

    You can also pass arguments:

    function Thing(name) {
        this.name = name;
    }
    Thing.prototype.doSomething = function(callback, salutation) {
        // Call our callback, but using our own instance as the context
        callback.call(this, salutation);
    }
    
    function foo(salutation) {
        alert(salutation + " " + this.name);
    }
    
    var t = new Thing('Joe');
    t.doSomething(foo, 'Hi');  // Alerts "Hi Joe" via `foo`
    

    Sometimes it’s useful to pass the arguments you want to give the callback as an array, rather than individually. You can use apply to do that:

    function Thing(name) {
        this.name = name;
    }
    Thing.prototype.doSomething = function(callback) {
        // Call our callback, but using our own instance as the context
        callback.apply(this, ['Hi', 3, 2, 1]);
    }
    
    function foo(salutation, three, two, one) {
        alert(salutation + " " + this.name + " - " + three + " " + two + " " + one);
    }
    
    var t = new Thing('Joe');
    t.doSomething(foo);  // Alerts "Hi Joe - 3 2 1" via `foo`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 509k
  • Answers 509k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Like this: private static readonly Dictionary<BookCode, Func<Book>> ctorsByCode = new… May 16, 2026 at 4:44 pm
  • Editorial Team
    Editorial Team added an answer They are definitely guidelines, but if you don't have confidence… May 16, 2026 at 4:44 pm
  • Editorial Team
    Editorial Team added an answer I don't think there is one in the framework itself.… May 16, 2026 at 4:44 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

tldr> Once a customer has been selected, how can all other controllers execute their
I need to execute a bunch of asynchronous methods (client SQLite database), and call
I have a bunch of connection related methods that I need to execute before
Hi All Nightowls out there :), I need to authenticate username and password provided
Here's my issue - I need to dynamically download several scripts using jQuery.getScript() and
Hi all I am not sure how to approach this problem. I have a
I have a Java application that I need to integrate our existing PHP website
I'm working with an existing javascript library that does an AJAX call and then
I have an onclick function which performs several tasks. In another JavaScript function I
I have several csv files that I need to transfer over to mdb format.

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.