Can someone please explain this piece of code which I have tried to decipher?
It still looks funny to me.
Because I need the Facebook login logic… and also because I like to understand what the code does… scope-wise etc…
Which function runs first, the outer one or the inner one?
Is this another way of writing plugin code?
var openid = {
},doJsFacebookLogin: function (a) {
window.FB.login(function (b) {
b.authResponse && (b = "/users/oauth/facebook/js?accessToken=" + encodeURI(b.authResponse.accessToken),
a && (b += "&returnUrl=" + encodeURI(a)), window.location = b)
}, openid.facebook_login_params)
},
Also what do the commas represent in the body off the function?
facebookLogin: function (a, b, c) {
c || ($("." + b).css("cursor", "wait"), openid.facebook_app_id ? openid.doJsFacebookLogin() : (this.setOAuthInfo(a.oauth_version, a.oauth_server), c || $("#openid_form").submit()))
},
etc...
When the outer one is run, it calls the inner one.
This is basically no different from, let’s say
– you yourself would call
foo()somewhere in your code, and that function then calls thealertmethod of the window object to bring up a little message saying “bar”.This is just a way of not actually having single statements and separate them with a semicolon – but of using expressions instead, and just separating them with a comma. (Which itself is an operator in JavaScript, but it does nothing more then denote a sequence of expressions, it does not logically connect them in any way.)
As long as a statement also makes for a valid expression, you can do that; although I can spot no actual benefit from doing it in this case – would be something different if the outcomes of the single expressions would be logically joined together by other logical operators as f.e. && or ||, and then the value of this whole expression would be used as a return value for that function, so that other functions/code parts calling it could determine success or failure of the function that way.
If you’re not familiar with what actually constitutes an expression in JavaScript, look for example here http://lib.ru/JAVA/javascr/expr.html#expr (or into the JS book of your choice).