我在某處讀到某個函數被調用時,編譯器會將所有可見變量放在堆棧上,這也與閉包有關,現在使用下面的代碼我不確定它是否' 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