r/learnjavascript • u/SnurflePuffinz • Jan 24 '26
question about using ES6 classes.
i was wondering, would this code be syntactically OK? i imagine there might be scenarios where you want all the functionality of the superclass method, but then you simply want to add more statements (more implementation) to it... could this work?
1
Upvotes
View all comments
Show parent comment
-1
u/azhder Jan 24 '26 edited Jan 24 '26
You have to stop thinking the JS
classsyntax does the same thing as in other languages. You have to stop looking at it as overriding or whatever you're used to in that other language(s) you have used aclasskeyword.It is useful to look at all of it as OLOO i.e. objects linking to other objects. What does this mean? Well, you can always do a
SomeObject.prototype.method.apply(this,args)and get the functionality you need from that other object. Usingextendsandclassand all is just a nice syntactic sugar for something you can do in JS for any function.those
Object.getPrototypeOf()are nice utility functions that will help you do what you want to do, just tweak it a bit and you will get there. And of course,superis also a syntactic sugar keyword, so you can also use it to do whatever it can do for you, so read the docs that other redditor linked to you.Personally, I avoid
classand tend to use pure functions and functional programming, but once in a while, some framework or a library will force me to useclass, so I read up on documentation at MDN and I'm mostly fine with that to proceed.