I'm having a problem with the scope of a public variable in javascript. The variable is declared in the main function (function Level) of my javascript class. The loadXML function is called from outside the class, but knows the this.layers variable. When my xml is loaded and redirected to another function the this.layers variable suddenly is undefined. Anyone having experience with this kind of problem.
var Level = (function()
{
function Level()
{
this.layers = 3;
}
Level.prototype.loadXML = function()
{
console.log(this.layers); //variable is defined!
$.get("xml/level_" + this.currentLevel + ".xml", Level.buildGrid);
};
Level.buildGrid = function(xml)
{
console.log(this.layers); //variable is undefined!
};
return Level;
})();
Thanks in advance.
Level.prototype.buildGrid = function()rather thanLevel.buildGrid...