squaremo/rabbit.js — Issue #11: Array.prototype and for loop
Author: cpdigger
Created: 2012-03-05 13:48:22+00:00
State: open

Hi,
i´m using the Array.prototype mechanism to extend arrays for some functions in my project. This causes the rabbit.js to crash.

Callstack:
/Users/cp/node_modules/rabbit.js/lib/sockets.js:168
if (ad.exchange.name == ex.name &&
^
TypeError: Cannot read property 'name' of undefined
at addToAdvertisements (/Users/cp/node_modules/rabbit.js/lib/sockets.js:168:24)
at Queue._openCallback (/Users/cp/node_modules/rabbit.js/lib/sockets.js:181:11)
at Queue._onMethod (/Users/cp/node_modules/amqp/amqp.js:1683:14)
at Queue._onChannelMethod (/Users/cp/node_modules/amqp/amqp.js:1348:14)
at Connection._onMethod (/Users/cp/node_modules/amqp/amqp.js:917:28)
at AMQPParser.onMethod (/Users/cp/node_modules/amqp/amqp.js:792:12)
at AMQPParser._parseMethodFrame (/Users/cp/node_modules/amqp/amqp.js:441:10)
at frameEnd (/Users/cp/node_modules/amqp/amqp.js:186:16)
at frame (/Users/cp/node_modules/amqp/amqp.js:171:14)
at AMQPParser.header [as parse] (/Users/cp/node_modules/amqp/amqp.js:159:14)

Code to reproduce:

var context = require('rabbit.js').createContext('amqp://localhost:5672');

Array.prototype.example = function (func) {
}

context.on('ready', function() {
var push = context.socket('PUSH');
push.connect('items', function() {
});
});

I think that happens because you iterate arrays by: for(var i in array) instead of for(var i =0;i