0

I am running following code : https://github.com/rjrodger/simpledb

var simpledb = require('simpledb');
var sys = require('sys');
sdb  = new simpledb.SimpleDB({keyid:'kye'
                    ,secret:'mysectkey'});
var str="select  *  from youngib where createdon is not null  order by createdon desc limit 10";                    
sdb.select (str,  function( error, result ) {
        console.log('attr1 = '+sys.inspect(error));
        console.log('result = '+sys.inspect(result));
    });

if i run this in seperate file it run but if i run in my project it gives me this error ,why this error coming?

{ Code: 'SignatureDoesNotMatch',
  Message: 'The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.' } 

the problem was that there i have declare

Array.prototype.in_array = function(p_val) {
    for(var i = 0, l = this.length; i < l; i++) {
        if(this[i] == p_val) {
            return true;
        }
    }
    return false;
}

due to this it was not executing the simpledb , i don't know why, if you know please tell me.

XMen
  • 29,384
  • 41
  • 99
  • 151

1 Answers1

2

If you extend Array.prototype you can get issues with for ... in loops.

For example:

Array.prototype.foo = 42;
var array = [1,2,3];
for (var index in array) {
    console.log(index + "," + array[index]);
    // logs 0,1 1,2 2,3 foo,42
}

The for in loop iterates over all properties. So basically your 3rd party code makes the assumption you have not extend on Array.prototype.

Extending native prototypes is bad practice for these reasons.

As for your in_array method you could use

var contains = someArray.some(function(val) {
    return val === p_val;
});

instead.

Raynos
  • 166,823
  • 56
  • 351
  • 396