Smallest event emitter
Smallest event emitter? $('<i>')
Written by Todd Wolfson
Related protips
3 Responses
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');
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#