Read-only JSON object in node.js -


I need to give the result as a JSON object to the user and I cache the results.

In some cases users change this result object and the revised version is constantly available to users. To avoid this, I am currently cloning the result, but it leads to a heavy overhead as a very heavy JSN object.

So I just want to make JSON to give results and to avoid the clone process. How to make a JSON object non-editable?

You can use Object.freeze () for it:

  Var obj = {a: 'a', b: 'b'}; Var freeze obz = object Freezes (OBJ); Freeze ozz A = 'C'; Console.log ("% j", Freeze Obze); // print {"a": "a", "b": "b"} console.log ("% j", obj); // print {"a": "a", "b": "b"} console.log (obj === freeze oblique); // Correctly prints  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -