Problems needing attention in the use of deep copy JSON.stringify method in javascript
This article mainly explains the "javascript in the deep copy of the JSON.stringify method in the use of the problems that need to pay attention to", the article explained the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "javascript in the deep copy of the JSON.stringify method in the use of the need to pay attention to" it!
After understanding the basic concepts of deep copy, we need to delve into some of the problems when using the deep copy JSON.stringify method.
1. The value of the copied object will disappear after serialization such as functions.
2. Copy Date type reference type will become a string.
3. Cannot copy properties of non-enumerable types.
4. The prototype chain of the object cannot be copied.
Example
Function Obj () {this.func = function () {alert (90)}; this.obj = {age: 18}; this.arr = [1,24,4]; this.und = undefined; this.reg = / 123 this.date; this.date = new Date (); this.NaN = NaN; this.infinity = Infinity This.sym = Symbol (2);} let obj0 = new Obj (); Object.defineProperty (obj0, "innumerble", {enumerable: false, value: "45678"}) console.log ("obj0", obj0) let obj1 = JSON.stringify (obj0); console.log ("obj1", obj1) Thank you for your reading, these are the contents of "the problems that need to be paid attention to when using the deep copy JSON.stringify method in javascript". After the study of this article, I believe you have a deeper understanding of the problems that need to be paid attention to when using the deep copy JSON.stringify method in javascript, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!