how to shallow clone javascript class


class myClass {
constructor() {
this.str = "String"; //Defining a string
this.number = 3; //Defining a number
}
}

var classReference = new myClass(); //Making new instance of class
var myObjectToCopy;

function copyClass() {
myObjectToCopy = JSON.parse(JSON.stringify(classReference)); //Converting class to a string then turning that string into an object
}

copyClass(); //Calling function to copy the class

//myObjectToCopy is now a copy of classReference

www.codegrepper.com
www.stackoverflow.com

how to remove an class in javascript


//remove a css class from an element
document.getElementById("myElementID").classList.remove("class_name");

document.getElementsByClassName("legend").style.display="none";

function removeClass() {
  var element = document.getElementById("myDIV");

  element.classList.remove("mystyle");
}

www.codegrepper.com
www.stackoverflow.com