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
Also in JavaScript:
- create json model online
- findindex js
- swap function javascript
- javascript sort function
- jquery cdn w3schools
- $(...).autocomplete is not a function
- npm ERR! Unexpected end of JSON input while parsing near '...ty":"sha512-2GTXt3b2Q'
- axios js
- remove last character from string jquery
- horizontal cards react bootstrap
- cubic root javascript
- ionicActionSheet decorator example
- how to print an array in javascript
- angular filter ngfor
- random item from array javascript
- bootstrap show modal on page load
- node list files in directory
- get header height jquery
- check for duplicates in array javascript
- npm i material ui
- how to keep scrolling with javascript
- passportjs mac req.user not saved
- sort array of objects javascript
- javascript check if element is visible on screen