-3

My code:

function myFunc(callback) { /*do stuff*/
    $('div').one('mouseover', function () {
        alert('mouseover');
        callback;
    });
}
$("div").click(function () {
    alert('clicked');
    myFunc(function () {
        alert('Callback');
    });
});

However, callback does not execute, nor is there an error in the console. How can I make this work?

Fiddle: http://jsfiddle.net/8Z66u/

GiantDuck
  • 1,076
  • 3
  • 13
  • 27

1 Answers1

6

You are forgetting to invoke with ()

function myFunc(callback) { /*do stuff*/
    $('div').one('mouseover', function () {
        alert('mouseover');
        callback(); // invoke
    });
}

Without (), you've just got a reference to the function callback but doing no action with it, so the line basically does nothing.

Paul S.
  • 61,621
  • 8
  • 116
  • 132