0

如何访问 function .exec(function(err, repl) { 中的响应参数?是否可以不创建局部变量?

#!/usr/local/bin/node

// Load the http module to create an http server.
var http = require('http');
var redis = require('redis');
var client = redis.createClient();


// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  client.multi([
    ['get', 'a'],
    ['get', 'b']
  ]).exec(function(err, repl) {
    console.log(err);
    console.log(repl[0]);
    response.end('Repl: ' + repl[0].toString());
  });
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
4

1 回答 1

1

只需访问它。参数被自动视为局部变量,内部函数可以访问其包含函数的局部变量(除非它用自己的同名变量隐藏它们)。

于 2013-04-20T17:23:35.323 回答