I have a typescript class
export class Restaurant {
constructor ( private id: string, private name: string ) {
}
public getId() : string {
return th
This seems to work for me:
var newObject = Object.assign(Object.create(oldObj), oldObj)
Object.create creates a new instance with empty properties Object.assign then takes that new instance and assigns the properties
A more robust version of a clone function
clone(obj) {
if(Array.isArray(obj)) {
return Array.from(obj);
} else {
return Object.assign(Object.create(obj), obj);
}
}