Last Updated: February 25, 2016
·
727
· twolfson

Smallest event emitter

Smallest event emitter? $('<i>')

3 Responses
Add your response

Nope, $([]) <= 3 bytes saved

over 1 year ago ·

Just tried yours but it seems to not be event emitting:

On a page like http://api.jquery.com/on/

Works:

var c = $('<i>');
c.on('abc', function () {
    console.log('123');
});
c.trigger('abc');

Does not work: =(

var c = $([]);
c.on('abc', function () {
    console.log('123');
});
c.trigger('abc');

Am I missing something?

over 1 year ago ·

Whoops...

No, you don't miss a thing. It was just my fault... Try to use an object instead of an array:

var c = $({});
c.on('abc', function () {
    console.log('123');
});
c.trigger('abc');

http://jsfiddle.net/xt7Bb/

over 1 year ago ·