Attribute Entity Reference always undefined in Promise?

hey everyone,

I am trying to setup a function to use a promise to create chain up a few actions. At the core I load a xml using fetch which is the reason for all the async stuff. However it seems that in every .then(function() { this.EntityAttribute } that entity attribute is undefined no matter how I use it

excerpt from my code:

BcardManager.attributes.add('xmlLoaderEntity', {type: 'entity', title: 'XML Loader'});
BcardManager.attributes.add('bcardTemplateEntity', {type: 'entity', title: 'Bcard Template'});
...
xmlLoader.loadXml().then(function(response) 
       {
       if (response)
           {
               for (i=0; i < xmlLoader.nodes.length; i++)
               {
                   var self = this;
                   var node = xmlLoader.getNode(i);
                   console.log(self);
                   console.log(self.bcardTemplateEntity);
               }
           }
       });

I already tried getting around it by moving the evaluate of this into that self variable because I saw that working in other cases but here bcardTemplateEntity keeps being undefined and I have no idea how to fix that…help?

Can you try this way?

BcardManager.attributes.add('xmlLoaderEntity', {type: 'entity', title: 'XML Loader'});
BcardManager.attributes.add('bcardTemplateEntity', {type: 'entity', title: 'Bcard Template'});
...
var self = this;
xmlLoader.loadXml().then(function(response) 
       {
       if (response)
           {
               for (i=0; i < xmlLoader.nodes.length; i++)
               {
                   var node = xmlLoader.getNode(i);
                   console.log(self);
                   console.log(self.bcardTemplateEntity);
               }
           }
       });

Can you post the full script please?