Interview questions often test objects of --js & compulsory in shallow vs. deep copy (clone copy) (lower)

Here it is mainly about deep copy:

Deep Copy: copy personal understanding is that all levels

1. restock objects like arrays and objects called these reference values. We begin first determine whether there are reference values ​​(arrays and small objects) large object,

   Then the reference value is an array or an object is determined

 

 2. Start then:

1 "Preparation:

Because the return type of the object and the array is object. So in order to distinguish them:

How to judge a Array: Object.prototype.toString.call ()

ToString using object can accurately determine what type , call () to change this point

L array type: print out will be [Object Array]

So this can be judged is not an array

 

2 "when traversing data aaa: Let's eliminate things on the prototype

          bbb: We find reference value (of type object is a reference value)

        ccc: Our judgment is an array or an object

3. On a close look at the code and results :( comment, read) in order to see more clearly in two screen display, knocking himself the right to write the code to the next full.

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/snowbxb/p/11593651.html