Skip to content

Commit

Permalink
Initialize listeners object in constructor in case fireEvent is calle…
Browse files Browse the repository at this point in the history
…d prior to addEventListener.
  • Loading branch information
ebryn committed Oct 20, 2011
1 parent eacd877 commit c1805f6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Resources/twitter.js
Expand Up @@ -38,6 +38,7 @@ exports.Twitter = (function(global) {
self.accessTokenKey = options.accessTokenKey;
self.accessTokenSecret = options.accessTokenSecret;
self.authorized = false;
self.listeners = {};

if (self.accessTokenKey && self.accessTokenSecret) {
self.authorized = true;
Expand Down Expand Up @@ -234,8 +235,9 @@ exports.Twitter = (function(global) {
* Fire an event
*/
Twitter.prototype.fireEvent = function(eventName, data) {
for (var i = 0; i < this.listeners[eventName].length; i++) {
this.listeners[eventName][i].call(this, data);
var eventListeners = this.listeners[eventName] || [];
for (var i = 0; i < eventListeners.length; i++) {
eventListeners[i].call(this, data);
}
};

Expand Down

0 comments on commit c1805f6

Please sign in to comment.