-1
我想知道是否有辦法讓單個語句中分配'myFields'的所有屬性?將屬性添加到函數返回的對象中?
這工作:
function fieldMap(namesString) {
var result = {};
var names = namesString.split(' ');
for (index in names) {
var name = names[index];
result[name] = name + '/text()';
}
return result;
}
var myFields = fieldMap('title rating author url');
myFields['cover']="@cover";
這不起作用:
var myFields = fieldMap('title rating author url')['cover']='@cover';
你是說你要分配相同的值,在對象的所有屬性一個單一的聲明? – 2012-03-05 14:11:19