js深拷贝函数

// 深拷贝函数
const _clone = (data) => {
  if (!data || !(data instanceof Object) || typeof data == 'function') {
    return data || undefined
  }
  let constructor = data.constructor
  let result = new constructor()
  for (var key in data) {
    if (data.hasOwnProperty(key)) {
      result[key] = _clone(data[key])
    }
  }
  return result
}

 

上一篇:kotlin类和对象


下一篇:《深度探索C++对象模型》笔记