对象clone

时间:2020-05-10 16:58:21   收藏:0   阅读:37
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)

  

原文:https://www.cnblogs.com/vmumu/p/12863908.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!