谁能帮我解释一下这段javascript代码
varHash={pair:function(){if(arguments.length%2!=0){_throw('Hash.pair:expectinganevenn...
var Hash = {
pair: function() {
if (arguments.length % 2 != 0) {
_throw('Hash.pair: expecting an even number of arguments');
}
var obj = {};
for (var i = 0; i < arguments.length; i += 2) {
var key = arguments[i];
var val = arguments[i + 1];
obj[key] = val;
}
return obj;
},
drop: function(obj, key) {
delete obj[key];
},
drop_fully: function(obj, key) {
if (bt.ie) {
var copy = {};
for (var temp in obj) {
if (key != temp) copy[temp] = obj[temp];
}
return copy;
} else {
delete obj[key];
return obj;
}
},
size: function(obj) {
var size = 0;
for (var key in obj) {
if (obj[key] != null) size++;
}
return size;
},
keys: function(obj) {
var keys = [];
for (var key in obj) {
keys.push(key);
}
return keys;
},
values: function(obj) {
var vals = [];
for (var key in obj) {
vals.push(obj[key]);
}
return vals;
},
num_keys: function(obj) {
var keys = [];
for (var key in obj) {
keys.push(parseInt(key));
}
return keys;
},
copy: function(obj) {
var copy = {};
for (var key in obj) {
copy[key] = obj[key];
}
return copy;
},
getn: function(obj, keys) {
if (obj == null) {
return null;
}
if (keys == '') {
return [];
}
keys = keys.split(' ');
var vals = [];
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var val = obj[key];
vals.push(val);
}
return vals;
}
};
主要是语法看不法 展开
pair: function() {
if (arguments.length % 2 != 0) {
_throw('Hash.pair: expecting an even number of arguments');
}
var obj = {};
for (var i = 0; i < arguments.length; i += 2) {
var key = arguments[i];
var val = arguments[i + 1];
obj[key] = val;
}
return obj;
},
drop: function(obj, key) {
delete obj[key];
},
drop_fully: function(obj, key) {
if (bt.ie) {
var copy = {};
for (var temp in obj) {
if (key != temp) copy[temp] = obj[temp];
}
return copy;
} else {
delete obj[key];
return obj;
}
},
size: function(obj) {
var size = 0;
for (var key in obj) {
if (obj[key] != null) size++;
}
return size;
},
keys: function(obj) {
var keys = [];
for (var key in obj) {
keys.push(key);
}
return keys;
},
values: function(obj) {
var vals = [];
for (var key in obj) {
vals.push(obj[key]);
}
return vals;
},
num_keys: function(obj) {
var keys = [];
for (var key in obj) {
keys.push(parseInt(key));
}
return keys;
},
copy: function(obj) {
var copy = {};
for (var key in obj) {
copy[key] = obj[key];
}
return copy;
},
getn: function(obj, keys) {
if (obj == null) {
return null;
}
if (keys == '') {
return [];
}
keys = keys.split(' ');
var vals = [];
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var val = obj[key];
vals.push(val);
}
return vals;
}
};
主要是语法看不法 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询