views:

197

answers:

1

So I am trying to consolidate a bunch of code into some nice NameSpaced functions, but am having a tough time getting it to all work together. For example, I have this (edited down for clarity):

YW.FB = function() {
   return {
        init: function(fncSuc, fncFail) {
                FB.init(APIKey, "/services/fbconnect/xd_receiver.htm");
                FB.Bootstrap.requireFeatures(["Connect"]);
                if(typeof fncSuc=='function') fncSuc();
    },

        login: function(fncSuc) {
            this.FB.Connect.requireSession(function() { 
                if(typeof fncSuc=='function') fncSuc();
            });
      },
        getUserInfo: function() {
            var userInfo = new Object;
            FB.Facebook.apiClient.users_getInfo([FB.Facebook.apiClient.get_session().uid],["name"],function(result, ex){
                userInfo.name = result[0]['name'];
                userInfo.uid = result[0]['uid'];
                userInfo.url  = FBName.replace(/\s+/g, '-');
                return userInfo;
            })
        }
   };
}();

On a normal page I can just do:

  FB.init(APIKey, "/services/fbconnect/xd_receiver.htm");
  FB.Bootstrap.requireFeatures(["Connect"]);
  var userInfo = new Object;
  FB.Facebook.apiClient.users_getInfo([FB.Facebook.apiClient.get_session().uid],["name"],function(result, ex){
                userInfo.name = result[0]['name'];
                userInfo.uid = result[0]['uid'];
                userInfo.url  = FBName.replace(/\s+/g, '-');
                return userInfo;
            })

And it works.

I have been trying to do:

YW.init();
YW.login();
YW.getUserInfo();

But it doesn't work. I keep getting 'FB.Facebook is undefined' from YW.getUserInfo I could be doing this all wrong too. So the FB.init, FB.Facebook stuff is using the facebook connect libraries. Am I doing this all wrong?

+1  A: 

If you look at the JavaScript that your browser has parsed in Firebug or a similar web debugger do you see the Facebook Connect JavaScript there? Looks like it's not in scope, and since FB is at the global level that means it's not in scope at all. Has nothing to do with namespaces. Global in JavaScript is global everywhere.

apphacker