我在某处读到某个函数被调用时,编译器会将所有可见变量放在堆栈上,这也与闭包有关,现在使用下面的代码我不确定它是否' d在像node.js这样的并发环境中工作。在javascript中调用堆栈变量
Product.prototype.list = function(body) {
body.options = {
hostname: endPoints.product,
path: '/applications/' + body.entityType
method: 'GET'
};
return remote.request(body)
.then(function(result){
body[body.entityType] = result;
return body;
});
};
现在如果使用promises同时调用以下两个函数,会发生闭包吗?例如
product.list({entityType: "coke"})
.then(console.log); //will this have {coke: []} or {pepsi: []}
product.list({entityType: "pepsi"})
.then(console.log);
我想这取决于产品是什么? – adeneo