var val ='hello world';
function outer() {
var val = 'bar';
return function inner() {
return val;
};
}
global.inner = outer();
32.
var getUserData =(function () {
var cache = {};
return function (userId, callback) {
if (cache[id]) {
process.nextTick(function () {
callback(cache[id]);
});
return;
}
getUser(id, function (data) {
cache[id] = data;
callback(data);
});
};
}());
33.
var getUserData =(function () {
var cache = new LRU({max: 100});
return function (userId, callback) {
if (cache.has(id)) {
var user = cache.get(‘id’);
process.nextTick(function () {
callback(user);
});
return;
}
getUser(id, function (data) {
cache.set(id, data);
callback(data);
});
};
}());
34.
app.get(‘/users/:id’, function (req,res) {
getUser(function (req.param(‘id’), data) {
user = data;
getOrderByUser(user.id, function (order) {
res.render({
user: user,
order: order
});
});
});
});
35.
app.get(‘/users/:id’, function (req,res) {
getUser(function (req.param(‘id’), data) {
user = data;
getOrderByUser(user.id, function (order) {
res.render({
user: user,
order: order
});
});
});
});
36.
app.get(‘/users/:id’, function (req,res) {
getUser(function (req.param(‘id’), data) {
var user = data;
getOrderByUser(user.id, function (order) {
res.render({
user: user,
order: order
});
});
});
});
37.
app.get(‘/users/:id’, function (req,res) {
getUser(function (req.param(‘id’), data) {
var user = data;
getOrderByUser(user.id, function (order) {
res.render({
user: user,
order: order
});
});
});
});
‘use strict’;