0
FB.Event.subscribe('auth.authResponseChange', function(response) 
{
 if (response.status === 'connected') 
{
    document.getElementById("message").innerHTML +=  "<br>Connected to Facebook";
    //SUCCESS

}    
else if (response.status === 'not_authorized') 
{
    document.getElementById("message").innerHTML +=  "<br>Failed to Connect";

    //FAILED
} else 
{
    document.getElementById("message").innerHTML +=  "<br>Logged Out";

    //UNKNOWN ERROR
}
}); 

I have a fair idea about the function on JavaScript as I used to code in c++ . but while trying to use Facebook SDK for JavaScript.

I don't get how the var response in

FB.Event.subscribe('auth.authResponseChange', function(response) { .... });

is initialised and its data members are used later.

And what are these kind of functions called?

0

2 Answers 2

1

They are called Callbacks.

What you see there is a callback that is an anonymous function - whereby you define a function but do not associate a name with it.

The code receiving the callback, in your case, the subscribe function, will decide when to call the function. It'll usually do so once it has finished it's own operations, returning control to your code to continue your logic.

The function is just like any other function and can receive arguments (in your case, the response variable). The code that calls this callback is in charge of passing these values. So it is the subscribe function that initializes and passes though the response argument.

Sign up to request clarification or add additional context in comments.

Comments

0

They are called callback functions and are registered for a certain type of event, when that event occurs, they are executed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.