0
如何將屬性動態添加到Javascript對象/類中?將XML名稱值對動態轉換爲對象屬性
我解析一個xml文件,爲xml元素中的每個名稱值對我試圖將該對添加爲一個Javascript對象的屬性。爲清晰起見,請參閱我的示例:
function MyObject(nType)
{
this.type = nType;
}
MyObject.prototype.parseXMLNode(/*XML Node*/ nodeXML)
{
var attribs = nodeXML.attributes;
for (var i=0; i<attribs.length; i++)
this.(attribs[i].nodeName) = attribs[i].nodeValue; // ERROR here
}
// Where the xml would look like
<myobject name="blah" width="100" height="100"/>