ccampbell / gator

Event delegation in Javascript
http://craig.is/riding/gators
492 stars 46 forks source link

Passing undefined as selector results in events never triggering, breaks other listeners #18

Open lazd opened 10 years ago

lazd commented 10 years ago

When passing undefined as the selector, the handler is never called (Fiddle):

// ✖ Clicks are NOT handled
Gator(window).on('click', undefined, function() {
    log('Gator got click with undefined selector');
});

However, it is called when selector is not passed at all (Fiddle):

// ✓ Clicks are handled
Gator(window).on('click', function() {
    log('Gator got click with undefined selector');
});

Curiously enough, doing both of the above at the same time results in neither working (Fiddle):

// ✖ Clicks are NOT handled
Gator(window).on('click', undefined, function() {
    log('Gator got click with undefined selector');
});
// ✖ Clicks are NOT handled
Gator(window).on('click', function() {
    log('Gator got click with undefined selector');
});