0
点赞
收藏
分享

微信扫一扫

js封装深拷贝方法


deepCopy: function (data) {
	if (data === null || data === undefined) {
			return null;
	}
	let result = Array.isArray(data) ? [] : {};
	if (data && typeof data === 'object') {
		for (let key in data) {
			if (data[key] && typeof data[key] === 'object') {
				result[key] = this.deepCopy(data[key]);
			} else {
				result[key] = data[key];
			}
		}
	}
	return result;
},


举报

相关推荐

0 条评论