JavaScript protection variable does not be modified by casual modification

Let’s share the code:

/ ** 1. If in rendertle, rendercontent, this total data can be modified, unsafe * improve * 1 . Provisions a way to modify the data, if you want to modify the data, you can only go this method ** action represents a command object, is a normal JS object, at least a field control command type Type, other fields, ** * / const Change_font_sile ‘; // Set a closure, protect the variables, call function createstore () {let appstate = {fontsize:’ 26px ‘, title: {text:’ title ‘, Color:’ Red ‘}, Content: {text:’ Category ‘, Color:’ Green ‘}} // The protection variable is modified, deep cloned let getState = () => json.parse (json.stringify (appstate)); //// Method of changing variables let dispatch = (action) => {switch (action.type) {copy change_font_sile: AppState.fontsize = action.fontsize; default: return;} // Return to the modified and value interface Return { GetState, Dispatch}} let store = createstore (); // Take the value function Function RendertITLE () {let title = document.queryselector (‘# title’); title.innerhtml = store.getState (). Title.Text; title.tele.color = store.getState (). Title.color; .fontsize = store.getState (). fontsize;} function render = document.Queryselector (“# content”); titleele.innerhtml = store.getState (). Content.Text; Titleele.Style.color = Store.getState (). Content.color; Titleele.Style.fontsize = store.getState (). fontsize;} function renderapp () {rendertle (); renderContent ()} // Modify the initial value in AppState, a single modified file Store.dispatch ({type: change_font_sile, fontsize: ’30px’}) renderapp ();
It is the JavaScript protection variable that Xiaobian introduced to you is not to be modified by the free modification. I hope that everyone will help. If you have any questions, please leave a message, the small package will reply to everyone. Thank you very much for your support of Tumi Cloud Website!

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment