Skip to content

Instantly share code, notes, and snippets.

@zzpmaster
Created June 16, 2021 02:30
Show Gist options
  • Save zzpmaster/e2b988af7d0f7940b885e037a1f2a9fb to your computer and use it in GitHub Desktop.
Save zzpmaster/e2b988af7d0f7940b885e037a1f2a9fb to your computer and use it in GitHub Desktop.
clone object
function shallowCopy<T>(origin: T): T {
return Object.assign(
Object.create(Object.getPrototypeOf(origin)),
origin
)
}
function shallowCopy2<T>(origin: T): T {
const obj = { ...origin };
Object.setPrototypeOf(obj, (origin as Object).constructor.prototype);
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment