以下声明是什么意思?
var line = {}, lines = [], hasmore;
我知道
lines = []
是一个数组,但我不知道其他的。
实际代码是使用 javascript xpcom 逐行读取文件
var line = {}, lines = [], hasmore;
do {
hasmore = istream.readLine(line);
lines.push(line.value);
} while(hasmore);
它创建了 3 个变量
var line = {}; // creates an object
var lines = []; // creates an array
var hasmore; // undefined
声明了 3 个变量(请参阅:在 JavaScript 中声明多个变量)。
var line = {} // creates an empty object literal
lines = [] // creates an empty array literal
hasmore // creates an empty undefined variable, which can hold any datatype
继续在您的控制台上尝试一下:
var line = {}, lines = [], hasmore;
然后访问它们,您将看到:
line is Object,
lines is an array
hasmore is undefined