tags:

views:

121

answers:

3

I have a javascript which I didn't write but I need to use it ..

    function function1()
    ... body..
    and at the end 
    I have this
 'callback': 'getListCallback'
  }

What does this callback mean and getListCallback = function(obj) is another function, does this mean that results from function1 are returned to function getListCallback?

Tnx

A: 

Yes, it should mean that

David Archer
+4  A: 

A callback function is a function that is going to be called later, usually when some event occurs. For example, when adding an event listener:

function callback(){
  alert("click");
}
document.body.addEventListener("click", callback, true);

In many cases you pass the callback function as an anonymous function:

setTimeout(function(){alert("It's been 1 second");}, 1000);

The code getListCallback = function1(obj); will not call getListCallback with the results of function1(obj). It will store whatever function1(obj) returns into getListCallback. If function1 returns a function, then you can call that function later, like so:

function function1(obj){
  return function(){
    alert("getListCallback was called. obj = "+obj);
  }
}
getListCallback = function1(1);
getListCallback();
Marius
A: 

normally a callback function means a function which will call after current function execution finished. This getListCallback = function(obj){// do something} is like assigning this "function(obj){//....}" to a variable which can use in any place where you need to use that function.

Manjula