impregnable fiend impregnable fiend - 1 year ago 39
Javascript Question

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
must execute only if
is correct. Dunno how properly write
statement here, any valuable help will be appreciated :)


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();