arguments.callee achieve deep copy

Tencent recently was watching a js knowledge inside the classroom learning videos, and then there is a deep copy of the question, so he did a little, use arguments.callee achieve a deep copy.

<script type="text/javascript">
			var obj = {
				"name":"小二",
				"age":18,
				"sex":"man",
				"grade":{
					"Arts Comprehensive":{
						"History": 100,
						"Politics": 80
					},
					"Comprehensive Li": {
						"Physics": 87,
						"Chemistry": 68
					}
				},
				"hobby":[[1,1,5,4],[2,3,4,5],[8,7,9,8]]
			};
			was obj1 = {};
			// implement deep copy
			function copyObject(o1,o2){
				was objc1 = O1;
				was objc2 = O2;
				for( prop in objc1){
					if(typeof(objc1[prop])+""!=="object"){
						// copy of the original value
						objc2 [near] = objc1 [near];
					}else if(Object.prototype.toString.call(objc1[prop])+""==="[object Array]"){
						// copy array
						objc2 [near] = [];
						arguments.callee(objc1[prop],objc2[prop])
					}
					else{
						// copy of the object
						objc2 [near] = {};
						arguments.callee(objc1[prop],objc2[prop])
					}
				}
				return objc2;
			}
			console.log (obj); // original object
			console.log (copyObject (obj, obj1)); // the copy target
		</script>

  

Achieve results:

Guess you like

Origin www.cnblogs.com/xiaojianwei/p/12209147.html