xmlToJSON uses single instance for every call, and every call modifies options object at parseXML function. Is it better to create onetime local copy of options for every call? Like this:
--- xmlToJSON.js-orig 2016-08-17 09:50:51.310936170 +0700
+++ xmlToJSON.js 2016-08-17 09:59:52.543327593 +0700
@@ -57,14 +57,16 @@
};
this.parseString = function(xmlString, opt) {
- return this.parseXML(this.stringToXML(xmlString), opt);
+ var localoptions = {}
+ opt = opt || {}
+ // initialize options
+ for (var key in options) {
+ localoptions[key] = (opt[key] === undefined) ? options[key] : opt[key];
+ }
+ return this.parseXML(this.stringToXML(xmlString), localoptions);
}
- this.parseXML = function(oXMLParent, opt) {
- // initialize options
- for (var key in opt) {
- options[key] = opt[key];
- }
+ this.parseXML = function(oXMLParent, options) {
var vResult = {},
nLength = 0,
sCollectedTxt = "";
@@ -154,7 +156,7 @@
sProp = oNode.nodeName;
}
- vContent = xmlToJSON.parseXML(oNode);
+ vContent = xmlToJSON.parseXML(oNode, options);
if (!vResult['_children']) vResult._children = [];
vResult._children.push(vContent);
vContent._tagname = sProp;
xmlToJSON uses single instance for every call, and every call modifies options object at parseXML function. Is it better to create onetime local copy of options for every call? Like this: