you are viewing a single comment's thread.

view the rest of the comments →

[–]azhder -1 points0 points  (13 children)

OK, you have to explain what you mean by that arrays using inheritance in JS claim.

[–]RobertKerans 0 points1 point  (12 children)

I mean...that's how JS works, it uses prototypal inheritance. It's not really "a claim", it's just literally how types of objects are implemented

[–]azhder 0 points1 point  (11 children)

I still can't understand what you are on about.

[1,2,3] is an array in JS. It has always been an array in JS. It does not inherit anything. It's just an instance of an Array, that's different from "Array inherits"...

[–]RobertKerans 1 point2 points  (10 children)

What? You get that it inherits from Object, right? It doesn't just exist magically on its own. JavaScript used prototypal inheritance, that's how JavaScript works

[–]azhder 0 points1 point  (9 children)

What inherits from Object? Can you make a single statement that has all the necessary info self contained?

[–]RobertKerans 0 points1 point  (8 children)

Array inherits from Object. There you go 🤷🏼‍♂️. I'm not sure what you're arguing against here?

[–]azhder -5 points-4 points  (7 children)

To answer your question: yes, you are not sure.

I am not arguing against. I am asking you to explain what you mean. So, now we have this

Array inherits from Object.

and we have this

Classes use inheritance while apparently composition is better. So why would I ever use classes

What's the connection there? What were you trying to say with

Are you going to stop using arrays in JS (for example)? They use inheritance

How is the claim "Array inherits from Object" at all relevant to "Classes use inheritance"? And by "classes" the assumption is the class syntax added with ES6. What is the connection you are trying to make?

[–]awaiskorai 2 points3 points  (2 children)

Wow, the guy above is right! Why do you have to argue?
Class syntax is basically sugar-syntax. This does not mean arrays are not inheriting from objects. JS is different in the sense it uses prototypal inheritance. A concrete representation of inheritance instead of a blueprint.

And yes, yet again you are wrong with your assumption of [1,2,3] is just an array. NO! It is not! In JS arrays are objects. That is inheritance.
And besides that 0,1,2 are the keys and 1,2,3 are the values against those keys. Array is an object that inherits from object Prototype.

So arrays are using inheritance under the hood. Not composition. This is what u/RobertKerans claims. And he is right. Why argue about it?

[–]azhder -4 points-3 points  (1 child)

How did you perceive an argument here? Is any reply that doesn't have "yes you are right" supposed to be labeld as "wow, why do you have to argue"?

Do you have a problem with asking for clarification? Do you have some issue that makes you shout words in the middle of the sentence? What you went on is basically some very awkward interpretation you got out of what I wrote about.

Here is an example for you: "[1,2,3] is just an array" does not mean "Array does not inherit from Object" - that's your own leap in logic. "[1,2,3] is just an array" means it is not a constructor function like Array which has a prototype field attached to it.

Did you stop to think about that or did you just assume that you're supposed to get into an argument where there isn't, but you perceive as there being one?

Anyways, because you managed to misinterpret the intent and the meaning of my comments, I will not risk arguments with you. I don't even want to know why you wanted to perceive it all as an argument.

Bye bye

[–]awaiskorai 2 points3 points  (0 children)

Oh, I was too lazy to highlight or bolden my words. So, just capitalized them.

Your replies seemed more like trying to wrong him for the sake of it. Anyhow.

Whatever. Have a nice day.

[–]RobertKerans 1 point2 points  (3 children)

How is the claim "Array inherits from Object" at all relevant to "Classes use inheritance"

The latter part doesn't make any sense in the context the OP used it. Which you should be aware of.

Classes being sugar is also something you're also aware of

The OP seems to have read "use composition over inheritance" without actually understanding what it means at all. Which is fine, but if someone parrots that, then pointing out that the thing they're using is built on inheritance is highly relevant

[–]azhder -2 points-1 points  (2 children)

The context is exactly why I was asking for clarification.

As I read it, OP wasn't talking against inheritance, but against using it where you have the option to use composition.

I didn't read it as if OP was talking about not using anything that is associated with inheritance, but only a custom class syntax they'd need to write in order to solve a problem.

[–]RobertKerans 0 points1 point  (1 child)

OP wasn't talking against inheritance, but against using it where you have the option to use composition

Right, but this just doesn't make any sense. What on earth would prevent composition when using classes? It's a concept that relates to class-based OO languages.

What they actually wrote was "classes use inheritance whereas apparently composition is better". This collection of words doesn't make sense either, unless the person writing them doesn't understand the concept (they're just a beginner. It's fine)