impregnable fiend
impregnable fiend

Reputation: 289

If first function is correct, got stuck in the simple situation

I know that my question is obviously ordinary, but I'm a bit newbie and dunno how shortly and, what most important, correctly perform that. So, I've got something like this:

 $('button').on('click', func1).on('click', func2);

As you can see I've got 2 'click' events on the same button, but func2 must execute only if func1 is correct. Dunno how properly write if statement here, any valuable help will be appreciated :)

Upvotes: 1

Views: 102

Answers (1)

VisioN
VisioN

Reputation: 145398

If I understand you right, and on click event you want to execute func2 only if func1 returns non-falsey value, then why not to transform it to:

$('button').on('click', function() {
    func1() && func2();

    // same as:
    // if (func1())
    //     func2();
});

Upvotes: 1

Related Questions