JSFiddle - React, Tailwind, and code Playground
by jfriend00
JavaScript
var Data = {
prop1: false,
prop2: true,
prop3: null,
// save initial values
init: function() {
var origValues = {};
for (var prop in this) {
if (this.hasOwnProperty(prop) && prop != "origValues") {
origValues[prop] = this[prop];
}
}
this.origValues = origValues;
},
// restore initial values
reset: function() {
for (var prop in this.origValues) {
this[prop] = this.origValues[prop];
}
}
}
Data.init();
Data.prop1 = true;
Data.prop2 = false;
Data.prop3 = "xxx";
Data.reset();
alert(Data.prop3);