retrieving from local storage and converting into class instance code example
Example: retrieving from local storage and converting into class instance
// Create some Point instances
let p1 = new Point(1,2);
// Store them in local storage
localStorage.setItem("p1", JSON.stringify(p1));
// Retrieve the data into new variables
let p1Data = JSON.parse(localStorage.getItem("p1"));
// convert p1Data back INTO a Point instance
let point1 = new Point();
point1.fromData(p1Data);
console.log(point1) // x: 1, y: 2