'Same function works in one js file while in other does not

I'm a begginer in javascript and I have one problem. The problem is that one function works in one javascript file and in the other no. In one of them I have a function which converts json to xml. This function works in that js archive. The problem comes in the other javascript file. I have to use that function on it, but that javascript files only has methods, so I've created a method with same code as the function, but it does not work there. It doesn't convert while in the other js yes. To use both method and function I've tried this.

var dat = JSON.stringify([{ "type": this.type, "sigma": this.sigma, "states": states }]);
return this.OBJtoXML2(dat);

How can I fix it?

1.js

function OBJtoXML(obj) 
{
    var xml = '';
    for (var prop in obj) 
    {
      xml += obj[prop] instanceof Array ? '' : "<" + prop + ">";

      if (obj[prop] instanceof Array) 
      {
        for (var array in obj[prop]) 
        {

          xml += "<" + prop + ">";
          xml += OBJtoXML(new Object(obj[prop][array]));
          xml += "</" + prop + ">";
        }
      } 
      else if (typeof obj[prop] == "object") 
      {

        xml += OBJtoXML(new Object(obj[prop]));

      } 
      else 
      {
     
        xml += obj[prop];
      }
      
    
      xml += obj[prop] instanceof Array ? '' : "</" + prop + ">";
    }
    var xml = xml.replace(/<\/?[0-9]{1,}>/g, '');
   
    return xml;
  }

2.js

export default class StateChart {
    constructor(type = 'AFD', sigma = 'ab', stateNaming = 'q') {
        this.type = type;
        this.sigma = sigma;
        this.sigmaExtended = (this.type === 'AFD' ? this.sigma : '\u03F5' + this.sigma);
        this.defaultName = stateNaming;
}
     OBJtoXML2(obj)    {

        var xml = '';
        for (var prop in obj) 
        {
          xml += obj[prop] instanceof Array ? '' : "<" + prop + ">";
    
          if (obj[prop] instanceof Array) 
          {
            for (var array in obj[prop]) 
            {
    
              xml += "<" + prop + ">";
              xml += OBJtoXML2(new Object(obj[prop][array]));
              xml += "</" + prop + ">";
            }
          } 
          else if (typeof obj[prop] == "object") 
          {
    
            xml += OBJtoXML2(new Object(obj[prop]));
    
          } 
          else 
          {
         
            xml += obj[prop];
          }
          
        
          xml += obj[prop] instanceof Array ? '' : "</" + prop + ">";
        }
        var xml = xml.replace(/<\/?[0-9]{1,}>/g, '');
       
        return xml;
       
     }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source