2013-11-27 59 views
0

下面的声明是什么意思?我知道lines = []是一个数组,但我不知道其他人。Javascript变量定义 - 澄清

实际的代码是使用JavaScript XPCOM

var line = {}, lines = [], hasmore; 
do { 
     hasmore = istream.readLine(line); 
     lines.push(line.value); 
} while(hasmore); 
+1

记住,JavaScript不跟踪变量类型在“编译期时间。” 'X = []; X = 3; x =“hi”;'完全有效(尽管不推荐)。变量的类型取决于你如何使用它,而不是你如何声明它。 –

+0

[可变声明与多个逗号分隔值是什么意思(例如var a = b,c,d;)]的可能重复(http://stackoverflow.com/questions/11076750/what-does-variable-declaration-with -multiple-comma-separated-values-mean-egv) –

+0

和[var myArray = \ [\],name ;?](http://stackoverflow.com/q/6232778/218196) –

回答

4

逐行读取文件中的行它创建3个变量

var line = {}; // creates an object 
var lines = []; // creates an array 
var hasmore;  // undefined 
1

声明3个变量(参见:Declaring Multiple Variables in 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 
0

来吧,试试这个控制台上:

var line = {}, lines = [], hasmore; 

然后访问它们,你会看到:

line is Object, 
lines is an array 
hasmore is undefined