1class myClass {
2 constructor() {
3 this.str = "String"; //Defining a string
4 this.number = 3; //Defining a number
5 }
6}
7
8var classReference = new myClass(); //Making new instance of class
9var myObjectToCopy;
10
11function copyClass() {
12 myObjectToCopy = JSON.parse(JSON.stringify(classReference)); //Converting class to a string then turning that string into an object
13}
14
15copyClass(); //Calling function to copy the class
16
17//myObjectToCopy is now a copy of classReference