maskedjellybean
maskedjellybean

Reputation: 719

Passing a function as argument of another function to nested function

Little confusing. From within function evenCard I'd like to call function autoFlip and pass it function evenBack as an argument. Then to complicate things further, autoFlip needs to pass the argument to another function nested within it and then call function evenBack. Is this possible? Thanks!

function evenCard() {
    autoFlip_toggle = true;     
    autoFlip(evenBack);
}

function autoFlip(back) {
    // do other stuff
    $(window).scroll(function() {
         if (autoFlip_toggle == true) {
           // Call evenBack somehow?
         }
     });
}

function evenBack() {
    // Does stuff
}

Upvotes: 0

Views: 108

Answers (2)

Devin Lynch
Devin Lynch

Reputation: 289

Call back(); within autoFlip.

function autoFlip(back) {
    // do other stuff
    $(window).scroll(function() {
         if (autoFlip_toggle == true) {
           back();
         }
     });
}

Upvotes: 2

Tom
Tom

Reputation: 4592

To call evenBack from the scroll function just write evenBack();

Upvotes: 1

Related Questions