JavaScript function always firing

a part of my code looks like this:

init: function(fncSuc, fncFail) {
            YAHOO.util.Get.script('http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php', {
            timeout:10,
            onSuccess: function() {
                FB.init('', "/services/fbconnect/xd_receiver.htm");
                alert('worked in the function');
                if(typeof fncSuc=='function') fncSuc();
            },
            onFailure: function() {
                alert('no work in the function');
                if(typeof fncFail=='function') fncFail();
            }
        });

the alert in onSucess and onFailure fire correctly, but fncFail(); and fncSuc(); ALWAYS fire. If I remove the if(typeof fncFail=='function') it works correctly, but then I'm not checking if functions are actually passed in or not. Why do they always fire? And how do I fix it.

Thanks!


interclubsAsked:
Who is Participating?
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
Like this?

function fncSuc() {}
function fncFail() {}

init: function(fncSuc, fncFail) {
            YAHOO.util.Get.script('http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php', {
            timeout:10,
            onSuccess: function() {
                FB.init('', "/services/fbconnect/xd_receiver.htm");
                alert('worked in the function');
                fncSuc();
            },
            onFailure: function() {
                alert('no work in the function');
                fncFail();
            }
        });

Open in new window

0
 
DeyhimCommented:
but then I'm not checking if functions are actually passed in or not !!!! use the body of these function to test if its passed or not...

remove this condition .. and check in functions "fncSuc, fncFail" body not from here


try that
0
 
interclubsAuthor Commented:
I'm not following. How can I check in the body of the functions if they're not always there. fncSuc and fncFail are not always passed in.
0
All Courses

From novice to tech pro — start learning today.