Phil Jackson
Phil Jackson

Reputation: 10288

Javascript - callback function

This seems in my head like it should work but I cant figure out why it doesn't:

(function ($) {

$.fn.extend({

    facebook: function (opts, callbackFnk) {

        var $this = this;
        ...
        ...
        ...

        $this.fbGetFriends = function( clback ){
            jsonUrl = fbMe + '/friends?access_token=' + token + '&callback=?';
            $.getJSON( jsonUrl, function( json ){
                console.log(json.data[0].name);
                clback.call(json);
            }); 
        }
        ...
        ...
        ...

In the console log the first name appears

In my other script:

var facebook = $.fn.facebook(
    { 
        myClientId  : '###############', 
        mySecret    : '##############' 
    }
);

facebook.fbOnLogin = function(){
    user = facebook.userDetails();
    token = facebook.getToken();
    facebook.fbGetFriends(function( json ){
        for ( var i in json ) {
            console.log( 'friends: ' + i + ' ' + json[i] );
        }
    });
}

In console log im getting nothing displayed and in previous tests its displaying errors data undefined.

Can anyone tell me where im going wrong?

regards

Upvotes: 1

Views: 204

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324790

You don't need clback.call, just clback(json) is enough.

Upvotes: 3

Related Questions