Skip to content
Advertisement

Javascript instantiate user-defined class object from given object does not set all properties

i have a user-defined class PaymentCoordinator in javascript with a constructor looking as shown below:

JavaScript

The last property in the constructor obj is used to instantiate a PaymentCoordinator object from a given object obj – which is like clone the given object. In the constructor, if a obj is given (obj !== false) i do the cloning as follows:

JavaScript

All properties of the given obj are set corretly – except for the one property categories which is a array of strings.

I also tried:

JavaScript

But this does also not set the categories property on the new created object.

If i plot the obj.categories i verified that the array contains strings.

Any ideas why this is not working?

Advertisement

Answer

Objects in JavaScript are passed by reference

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement