clone
Creates a shallow copy of the given object/value.
198 bytes
since v12.1.0
Usage
Creates a shallow copy of the given object or array.
Notably, built-in objects like Map, Set, Date, and others are not supported.
import * as import _
_ from 'radashi'
const const ra: { name: string; power: number;}
ra = { name: string
name: 'Ra', power: number
power: 100,}
const const gods: { name: string; power: number;}[]
gods = [const ra: { name: string; power: number;}
ra]
import _
_.function clone<{ name: string; power: number;}>(obj: { name: string; power: number;}): { name: string; power: number;}
Creates a shallow copy of the given object/value.
clone(const ra: { name: string; power: number;}
ra) // => copy of raimport _
_.function clone<{ name: string; power: number;}[]>(obj: { name: string; power: number;}[]): { name: string; power: number;}[]
Creates a shallow copy of the given object/value.
clone(const gods: { name: string; power: number;}[]
gods) // => copy of godsDifferences from spread syntax
The clone function is similar to spread syntax (e.g. {...obj}), but it also preserves the prototype of the original object. If a constructor property exists on the original prototype, it will be called with the new keyword to create a new instance, and all properties will then be copied over to it.
Unlike spread syntax, clone also supports cloning arrays.