In my JavaScript code, I have a custom class called PaymentCoordinator
with a constructor defined as follows:
constructor(
private amount: number,
private description: string,
private title: string,
private transactionType: string,
private creditors: Array<any>,
private categories: Array<string>,
private startdate: Date = undefined,
private enddate: Date = undefined,
obj: any = false)
The final property in the constructor, obj
, is used to create a new instance of PaymentCoordinator
based on a provided object, essentially cloning it. If an obj
is passed (when obj !== false
), the cloning process occurs like this:
obj && Object.assign(this, obj);
While all properties of the given obj
are successfully set, there seems to be an issue with the categories
property, which is an array of strings.
I also attempted the following approach:
obj && Object.assign(this, obj);
this.categories = obj.categories
Unfortunately, even this method does not properly assign the categories
property to the newly created object.
After checking the contents of obj.categories
, I can confirm that the array does indeed contain strings.
Any insights into why this behavior is occurring?