Answers for "retrieving from local storage and converting into class instance"

0

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
Posted by: Guest on April-23-2021

Code answers related to "retrieving from local storage and converting into class instance"

Browse Popular Code Answers by Language