Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

alter Array prototype so the nodejs implementation of EventEmitter re…

…mains untouched
  • Loading branch information...
commit 9fa144510a2a5e8f2d26777676735e6fb59d7675 1 parent 6a8f807
@dejoya dejoya authored
Showing with 18 additions and 19 deletions.
  1. +18 −19 index.js
View
37 index.js
@@ -1,28 +1,27 @@
(function(exports) {
var process = { EventEmitter: function() {} };
- var isArray = Array.isArray || function(obj){ return Object.prototype.toString.call(obj) === "[object Array]" };
- var indexOf = (function(){
- if (Array.prototype.indexOf !== undefined){
- return function(array, item){
- return array.indexOf(item);
- };
- }
- else {
- return function(array, item){
- for ( var i = 0, length = array.length; i < length; i++ ) {
- if ( array[ i ] === item ) {
- return i;
- }
+
+ if (typeof Array.isArray !== "function"){
+ Array.isArray = function(obj){ return Object.prototype.toString.call(obj) === "[object Array]" };
+ }
+
+ if (!Array.prototype.indexOf){
+ Array.prototype.indexOf = function(item){
+ for ( var i = 0, length = this.length; i < length; i++ ) {
+ if ( this[ i ] === item ) {
+ return i;
}
-
- return -1;
}
- }
- }());
+
+ return -1;
+ };
+ }
// Begin wrap of nodejs implementation of EventEmitter
- var EventEmitter = exports.EventEmitter = process.EventEmitter;
+ var EventEmitter = exports.EventEmitter = process.EventEmitter;
+
+ var isArray = Array.isArray;
EventEmitter.prototype.emit = function(type) {
// If there is no 'error' event listener then throw.
@@ -124,7 +123,7 @@
var list = this._events[type];
if (isArray(list)) {
- var i = indexOf(list, listener);
+ var i = list.indexOf(listener);
if (i < 0) return this;
list.splice(i, 1);
if (list.length == 0)
Please sign in to comment.
Something went wrong with that request. Please try again.