你好
我失去了大约4个小时调试奇怪的问题我的工作流程是
var config = {
someKey : [
'valueA','valueB'
]
};
function anAction()
{
// some code and loops like a maze, then
async.each(config.someKey,function(configKey)
{
// another maze+asynchronous , and because off my bad luck i use configKey inside if statement and change it
});
}
所以循环之后async.each改变了我的配置值,就好像它是通过引用调用
所以我的问题 如果它在javascript中的默认行为是使用引用调用还是它的异步行为?
修改
它与async
无关请测试此示例
var crazy = [
{key:'value'}
];
// safe code no change
crazy.forEach(function(item)
{
item = 'new value';
});
console.log(crazy);
// bad code do change
crazy.forEach(function(item)
{
item.key = 'new value';
});
console.log(crazy);