对象clone

Object.prototype.clone = function(){
		var o = this.constructor === Array ? [] : {}
		for(var e in this){
			o[e] = typeof this[e] == 'object' ? this[e].clone() : this[e]
		}
		return o
	}
	
	let a = {
		a: [1, 2],
		b: {
			a:[2,3]
		}
	}
	let b = a.clone()
	console.log(b)

  

posted @ 2020-05-10 16:27  微木Vmumu  阅读(139)  评论(0编辑  收藏  举报