我想知道下面的行是什么样的语法被调用。多个变量分配给Javascript中的一个变量?
var that = {}, first, last;
注:我发现本网站上关于这个问题的帖子,但他们说[]已经围绕变量被添加在右手边,使其数组。但下面的代码确实有效。
代码:
var LinkedList = function(e){
var that = {}, first, last;
that.push = function(value){
var node = new Node(value);
if(first == null){
first = last = node;
}else{
last.next = node;
last = node;
}
};
that.pop = function(){
var value = first;
first = first.next;
return value;
};
that.remove = function(index) {
var i = 0;
var current = first, previous;
if(index === 0){
//handle special case - first node
first = current.next;
}else{
while(i++ < index){
//set previous to first node
previous = current;
//set current to the next one
current = current.next
}
//skip to the next node
previous.next = current.next;
}
return current.value;
};
var Node = function(value){
this.value = value;
var next = {};
};
return that;
};