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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Michel PlungjanIT 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.