Here is my object and I have defined all the properties and functions but it still gives me this error result is not defined.
Here is my code
You should use this, but it might be easier if you use a constructor so you have access to the properties in all methods:
function Xml(to, from, url, result) {
this.to = to || null;
this.from = from || null;
this.url = url || null;
this.result = result || null;
// init logic
}
Xml.prototype = {
parseXml: function (xml) {
console.log('xml: ' + $(xml));
this.result = $(xml);
},
getResult: function () {
console.log('Result: ' + this.result);
return this.result;
}
...
}
var xml = new Xml(to, from, url, result); // init
Edit: An object literal might not be the best option. Your case is more suited for a constructor like above, or a module pattern if you want to avoid the this confusion:
function Xml() {
var xml = {}
, to = null
, from = null
, url = null
, result = null;
xml.parseXml = function( xml ) {
...
};
...
return xml;
}
var xml = Xml();