Skip to content

Commit 3fb2dc2

Browse files
committed
Fixes #9: use Object.create(null) over {}
1 parent 0d51fe3 commit 3fb2dc2

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
export default function mitt(all) {
66
// Arrays of event handlers, keyed by type
7-
all = all || {};
7+
all = all || Object.create(null);
88

99
// Get or create a named handler list
1010
function list(type) {

test/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('mitt', () => {
1414
let events, inst;
1515

1616
beforeEach( () => {
17-
events = {};
17+
events = Object.create(null);
1818
inst = mitt(events);
1919
});
2020

@@ -32,6 +32,13 @@ describe('mitt', () => {
3232
expect(events).to.have.property('foo').that.deep.equals([foo]);
3333
});
3434

35+
it('should register handlers for any type strings', () => {
36+
let foo = () => {};
37+
inst.on('constructor', foo);
38+
39+
expect(events).to.have.property('constructor').that.deep.equals([foo]);
40+
});
41+
3542
it('should append handler for existing type', () => {
3643
let foo = () => {};
3744
let bar = () => {};

0 commit comments

Comments
 (0)