Skip to content

Commit ba0a309

Browse files
author
Rob Griffiths
committed
added 'addEventListener'
1 parent d754e42 commit ba0a309

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/XMLHttpRequest.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ exports.XMLHttpRequest = function() {
128128
/**
129129
* Gets all the response headers.
130130
*
131-
* @return string
131+
* @return string
132132
*/
133133
this.getAllResponseHeaders = function() {
134134
if (this.readyState < this.HEADERS_RECEIVED || errorFlag) {
@@ -349,6 +349,14 @@ exports.XMLHttpRequest = function() {
349349
this.readyState = this.UNSENT;
350350
};
351351

352+
var listeners = {};
353+
this.addEventListener = function(event, callback) {
354+
if (!(event in listeners)) {
355+
listeners[event] = [];
356+
}
357+
listeners[event].push(callback);
358+
};
359+
352360
/**
353361
* Changes readyState and calls onreadystatechange.
354362
*
@@ -359,5 +367,12 @@ exports.XMLHttpRequest = function() {
359367
if (typeof self.onreadystatechange === "function") {
360368
self.onreadystatechange();
361369
}
370+
371+
if ("readystatechange" in listeners) {
372+
var count = listeners["readystatechange"].length, i = 0;
373+
for(; i < count; i++) {
374+
listeners["readystatechange"][i].call(self);
375+
}
376+
}
362377
};
363378
};

0 commit comments

Comments
 (0)