From c950e85c8248800f321e280c16a48f15a35e8d4a Mon Sep 17 00:00:00 2001 From: Juuso Lapinlampi Date: Wed, 18 Nov 2015 15:42:31 +0000 Subject: Workaround undefined length TypeError in cheesesteak this._events[evt].length would run into JavaScript scope issues in EventEmitter.prototype.emit function for-loop. This is an attempt to work around the issue to resolve an innocent looking TypeError. The code seems to work without this patch, but I can't spot if this is some dead code or know what to do with it. Due to technical debt, some sacrifice had to be made in readability for fixing this bug. This bug was introduced in commit 575b78b. For future improvement, this function and other functions in the file should be refactored or replaced with a more efficient implementation. --- js/cheesesteak.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/cheesesteak.js') diff --git a/js/cheesesteak.js b/js/cheesesteak.js index 905c5f3..90802d3 100644 --- a/js/cheesesteak.js +++ b/js/cheesesteak.js @@ -85,14 +85,14 @@ }; EventEmitter.prototype.emit = function(evt) { - var len = this._events[evt].length; var i; + var len; if (!this.hasOwnProperty('_events') || evt in this._events === false) { return; } - for (i = 0; i < len; i++) { + for (i = 0, len = this._events[evt].length; i < len; i++) { this._events[evt][i].apply(this, Array.prototype.slice.call(arguments, 1)); } -- cgit v1.2.3