scottcorgan / tiny-emitter

A tiny (less than 1k) event emitter library
MIT License
935 stars 67 forks source link

checking e is array instead of just defined #32

Closed yaodingyd closed 5 years ago

yaodingyd commented 6 years ago

This fix if we are trying to intentional overwrite object's native properties as event name, like 'toString'

scottcorgan commented 6 years ago

Do you have an example?

yaodingyd commented 6 years ago

Sure!

var emitter = new Emitter();
emmitter.on('toString', function(){
    console.log('I just want to use toString as an event name')
})

Currently it would show (e[name] || (intermediate value)(intermediate value)).push is not a function because e.toString is truthy, but we really want an array.

yaodingyd commented 5 years ago

@scottcorgan any update?