2021年2月2日星期二

Two JSON File Comparison

I am new to JS and I got the below code from one of the internet forums and it's not working if I invoke the function from the Javascript class like below. When I try to execute I get the below errors and I am unable to figure out whats the reason. Can someone please help me with what I am missing here?

Error Message

var person1 = {    FirstName: "First Name1",    LastName: "Last name1",    Age: 30,    EMailAddresses: [      "FirstName.LastName@msn.com"    ],    Children: [{      FirstName: "Child First Name1",      LastName: "Child Last Name1",      Age: 2    }, {      FirstName: "Child First Name2",      LastName: "Child Last Name2",      Age: 5    }]  };    var person2 = {    LastName: "LastName2",    Age: 33,    EMailAddresses: [      "LastName2@gmail.com",      "LastName2@hotmail.com"    ],    Children: [{      FirstName: "Child First Name1",      LastName: "Child Last Name1",      Age: 3    }, {      FirstName: "Micky",      LastName: "Mouse",      Age: 5    }]  };        class MasterClass {    async getDifferencs(objectA, objectB) {        var propertyChanges = [];      var objectGraphPath = ["this"];        (function(a, b) {        if (a.constructor == Array) {          for (var i = 0; i < a.length; i++) {            objectGraphPath.push("[" + i.toString() + "]");            arguments.callee(a[i], b[i]);              objectGraphPath.pop();          }        } else if (a.constructor == Object || (a.constructor != Number &&            a.constructor != String && a.constructor != Date &&            a.constructor != RegExp && a.constructor != Function &&            a.constructor != Boolean)) {          for (var property in a) {            objectGraphPath.push(("." + property));            if (a[property].constructor != Function) {              arguments.callee(a[property], b[property]);            }            objectGraphPath.pop();          }        } else if (a.constructor != Function) { // filter out functions          if (a != b) {            propertyChanges.push({              "Property": objectGraphPath.join(""),              "ObjectA": a,              "ObjectB": b            });          }        }      })(objectA, objectB);      return propertyChanges;    }  }    var my_class = new MasterClass();  var differences = my_class.getDifferencs(person1, person2);    console.log(differences);
https://stackoverflow.com/questions/66021068/two-json-file-comparison February 03, 2021 at 11:59AM

没有评论:

发表评论