如果我调用函数传递参数参数(其中调用异步函数B),异步函数B的回调函数C将能够使用给定的参数参数函数A?如果是的话,如果在函数B start和回调C之间的时间内调用,我会重新调用函数A吗?在调用函数的回调函数中使用参数
实施例:
function A(param) {
value1 = param;
doc = "hello";
//this is the async function B;
database.insert(doc, function() {
//this is the invoked callback C when the async function is solved.
console.log(value1)
//can i log value1? yes. if yes, will this change if i re-invoke
//function A before the callback is invoked or two different processes will start?
})
}
A('hello');
A('not hello');
想知道这一点,如果在第二时间函数的先前调用的回调函数调用之前,将打印在控制台右侧的值:
你好; 不是你好;
并且从不 不是你好; 不是你好;
导致第二次调用第一次感染。
**用'var'声明你的局部变量** – Pointy
先谢谢你。这是需要正确的工作还是只是建议? @Pointy – Morrisda
这只是一个非常重要的习惯,也是一个重要的理解。 – Pointy