The main issue I am trying to solve is that parent and subclass have a property with the same name. Is it possible to somehow merge the subclass property with the parent?
One idea I have is to have a constructor in the parent which would set a prototype value, but it does not work: jsitor.com/JVMU5NzK8W
Thank you, sure, but I was trying to find something with a dark theme.
And with more than 1 file JavaScript like CodeSandbox but simpler.
@ParkingMaster This was the main purpose indeed, so to have some kind of default property values in the parent and allow the child to override some of them.
May I ask is there any example which would demonstrate the logic you mention?: "store the child's target class, remove the child's target class, append the stored class to...'?
It's just a plain ECMAScript6 syntax code or the sugar wrappers around the underlying Object methods I am still trying to gain knowledge about.
By "parent" class I meant the one the subclass extends. E.g. class B extends A, where A is the super-class (parent if an instance), and B - sub-class (child if an instance).
@Artfaith Please don't post unformatted code - use the up arrow to edit your post, then hit Ctrl + K to format the code in that post. See the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
You're correct. I wanted to merge some property indeed, so to allow the child have its own custom values and allow it to get pre-defined default values from the extended one.
In the result, the child constructor like "new B({a: 3})l" would result in {a: 3, b: 1} where the b property was in the parent prior merging.
More to that, this allows for deep merging and override deeper values if required in the option hierarchy.
Like: const b = new B({a: {c: 2}}); ~ b.test == {a: {c: 2, d: 3}, b: 1}; // In the case test is the "default" property being merged.
What you have to do is store all of B's custom properties (before it's created) in another property called custom, then after B() is called, loop through all of the sub properties in .custom, and append them to A's properties when it is created
I tried to make my answer simple enough but let me know how it goes
@Regokonda Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
I am trying something in typescript and trying to find a solution. I have an object Address{'30 Collins st','Burnley','Sydney','NSW',3000 } how can I convert this into a string with full address
@ParkingMaster .toSting() on a plain object produces the string "[object Object]"
@Regokonda That's not really a valid object. It's missing keys. If you had some keys, like {key1: '30 Collins st', key2: 'Burnley', key3: 'Sydney', key4: 'NSW', key5: 3000 } then the easiest way convert it to a regular address with string template:
@Wietlol that's cool. Don't know why James can't do it
@VLAZ-onstrike- I don't know typescript so sorry for the mistake. Obviously toString doesn't work on an object in Javascript, but it seems to work right in typescript
||request httpbin.org/post POST "'parameter': 'value', 'example': 1"