以下是我的代码
var http = require('http');
var fs = require('fs');
var arguments = process.argv;
var path = process.argv[3];
var path2 = arguments[3];
var server = http.createServer(
function (req, res)
{
console.log('path1'+path);
console.log('path2'+path2);
console.log('path3'+arguments[3]);
var fileStream = fs.createReadStream(arguments[3]);
fileStream.pipe(res);
}
);
server.listen(arguments[2]);
如果我将路径或路径2传递给fs.createReadStream(),我的代码可以工作,但如果我传递参数[3],它会失败,console.log(path3)也会打印undefined。我不明白这一点。有人请解释一下。感谢。
答案 0 :(得分:3)
恭喜您刚刚发现了JS attribute
的论据function object
,请参考MDN Docs了解更多信息
arguments 对象是一个类似于Array的对象,对应于传递给函数的参数。
尝试console.log(arguments)
或
var http = require('http');
var fs = require('fs');
var parguments = process.argv;
var path = process.argv[3];
var path2 = parguments[3];
var server = http.createServer(
function (req, res)
{
console.log('path1'+path);
console.log('path2'+path2);
console.log('path3'+parguments[3]);
var fileStream = fs.createReadStream(parguments[3]);
fileStream.pipe(res);
}
);
server.listen(parguments[2]);
请注意我已将arguments
的名称更改为parguments
答案 1 :(得分:0)
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"hh:mm a"];// change here as per your need
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
NSString *stringFromDate = [formatter stringFromDate: globalDateTime];