/**
 * 深層複製物件的巢狀內容；所有深度的物件都會被建立副本，不會複製參照。
 */ export function deepCopy < T > ( target , ... sources ) { for ( let s of sources ) { if ( ! ( s instanceof Object ) ) continue ; let keys = Object . keys ( s ) as ( keyof T ) [ ] ; for ( let k of keys ) { let v = s [ k ] as T [ typeof k ] ; if ( ! ( v instanceof Object ) ) { target [ k ] = v ; } else if ( target [ k ] instanceof Object && target [ k ] != v ) { target [ k ] = deepCopy ( target [ k ] , v ) ; } else { target [ k ] = clone ( v ) ; } } } return target ; } /** 複製一個物件 */ export function clone < T > ( source ) { let r = source instanceof Array ? [ ] : { } ; return deepCopy ( r as T , source ) ; }