I read somewhere that whenever a function gets called, the compiler puts all the visible variables on a stack, somewhat related to closures as well, now with the following code I'm not really sure if it'd work in a concurrent environment like node.js.
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;
});
};
Now if the following two function gets called concurrently using promises, will a closure occur? For instance
product.list({entityType: "coke"})
.then(console.log); //will this have {coke: []} or {pepsi: []}
product.list({entityType: "pepsi"})
.then(console.log);