我正在运行以下代码: 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));
});
如果我在单独的文件中运行它运行但是如果我在我的项目中运行它会给我这个错误,为什么会出现这个错误?
{ 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.' }
问题在于我已声明
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;
}
因此没有执行simpledb,我不知道为什么,如果你知道请告诉我。
答案 0 :(得分:2)
如果您延长Array.prototype
,则可能会遇到for ... in
循环问题。
例如:
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
}
for循环迭代所有属性。所以基本上你的第三方代码假设你没有延伸到Array.prototype
。
由于这些原因,扩展原生原型是不好的做法。
至于您可以使用的in_array
方法
var contains = someArray.some(function(val) {
return val === p_val;
});
代替。