Assume that Emiter#_evenTypes is not always defined.

Resolves https://github.com/paperjs/paper.js/pull/674#discussion_r30042363
This commit is contained in:
Jürg Lehni 2015-05-13 20:21:22 +02:00
parent 75c6db6986
commit 6b428f5a37

View file

@ -23,7 +23,8 @@ var Emitter = {
this.on(key, value);
}, this);
} else {
var entry = this._eventTypes[type],
var types = this._eventTypes,
entry = types && types[type],
handlers = this._callbacks = this._callbacks || {};
handlers = handlers[type] = handlers[type] || [];
if (handlers.indexOf(func) === -1) { // Not added yet, add now.
@ -45,7 +46,8 @@ var Emitter = {
}, this);
return;
}
var entry = this._eventTypes[type],
var types = this._eventTypes,
entry = types && types[type],
handlers = this._callbacks && this._callbacks[type],
index;
if (handlers) {
@ -103,7 +105,8 @@ var Emitter = {
key = install ? 'install' : 'uninstall';
for (var type in handlers) {
if (handlers[type].length > 0) {
var entry = this._eventTypes[type],
var types = this._eventTypes,
entry = types && types[type],
func = entry && entry[key];
if (func)
func.call(this, type);