aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gudulin <[email protected]>2017-01-16 22:05:05 +0100
committerAlexander Gudulin <[email protected]>2017-01-16 22:05:05 +0100
commit3fb2dc21223b414afc6f1fa3c8bc8fc7de2d48d5 (patch)
tree61907d336e05204720049872ef746eb1c9f2d5fa
parent0d51fe34ce1b1ccf7c99726d9c577a40ea840da7 (diff)
Fixes #9: use Object.create(null) over {}
-rw-r--r--src/index.js2
-rw-r--r--test/index.js9
2 files changed, 9 insertions, 2 deletions
diff --git a/src/index.js b/src/index.js
index 36b25f1..bc9532f 100644
--- a/src/index.js
+++ b/src/index.js
@@ -4,7 +4,7 @@
*/
export default function mitt(all) {
// Arrays of event handlers, keyed by type
- all = all || {};
+ all = all || Object.create(null);
// Get or create a named handler list
function list(type) {
diff --git a/test/index.js b/test/index.js
index 8055544..4efa75e 100644
--- a/test/index.js
+++ b/test/index.js
@@ -14,7 +14,7 @@ describe('mitt', () => {
let events, inst;
beforeEach( () => {
- events = {};
+ events = Object.create(null);
inst = mitt(events);
});
@@ -32,6 +32,13 @@ describe('mitt', () => {
expect(events).to.have.property('foo').that.deep.equals([foo]);
});
+ it('should register handlers for any type strings', () => {
+ let foo = () => {};
+ inst.on('constructor', foo);
+
+ expect(events).to.have.property('constructor').that.deep.equals([foo]);
+ });
+
it('should append handler for existing type', () => {
let foo = () => {};
let bar = () => {};