You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my application I have a series of model classes and they all extend the same base class. The BaseClass has a constructor implemented that when given a key value map will set the values of that map on the class.
Where my problem comes in is when extending the base class, If I define any default values for properties in the child class they will always override the values set by the constructor since I'm letting the parent class set the values, and that will always run first, then the defaults after.
A constructed PersonClass will always have 'Derek' as the firstName value regardless of what is passed to the constructor.
i.e.
varperson=newPersonClass({firstName: 'Jack'});console.log(person.firstName);// logs Derek, not Jack
If not for the default property value being set the property would work fine. I have put together a CodePen to see a working example, http://codepen.io/dotDeeka/pen/bEErjJ?editors=001. If you view the compiled JavaScript you can see quickly that the child class calls the parents constructor before setting the default property values.
I know languages like Java require you call the parent class as the very first thing in a constructor so I'm assuming that is what you were going for here.
Any thoughts?
The text was updated successfully, but these errors were encountered:
In my application I have a series of model classes and they all extend the same base class. The BaseClass has a constructor implemented that when given a key value map will set the values of that map on the class.
Something like:
base-class.ts
Where my problem comes in is when extending the base class, If I define any default values for properties in the child class they will always override the values set by the constructor since I'm letting the parent class set the values, and that will always run first, then the defaults after.
For example:
Given the model
person.ts
A constructed PersonClass will always have 'Derek' as the firstName value regardless of what is passed to the constructor.
i.e.
If not for the default property value being set the property would work fine. I have put together a CodePen to see a working example, http://codepen.io/dotDeeka/pen/bEErjJ?editors=001. If you view the compiled JavaScript you can see quickly that the child class calls the parents constructor before setting the default property values.
I know languages like Java require you call the parent class as the very first thing in a constructor so I'm assuming that is what you were going for here.
Any thoughts?
The text was updated successfully, but these errors were encountered: