Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAdiv Abramson
6,919 PointsWill JS one day have syntactic sugar equivalent to the Java method of specifying inheritance?
The prototype inheritance syntax is awkward to say the least. I hope at some point the makers of Javascript will add an extends or inherits keyword to the language so that the mechanism of inheritance becomes less unwieldy.
function childObject() {
this.extends(parentObject);
}
3 Answers
jesdavpet
21,489 PointsGood news Adiv -- more formal class / inheritance language features are rolled into the ECMAScript 6 standard! I think that's what you are hoping for?
Coming back to JavaScript after a lot of time developing in Java, I too really missed defining class relationships explicitly. Although flexible, the JavaScript way just seems sloppy in comparison.
Justin Horner
Treehouse Guest TeacherHello Adiv,
You might be interested in Typescript. Typescript "lets you write JavaScript the way you really want to". It compiles to plain Javascript. You can check it out here.
I hope this helps.
Joshua Erskine
7,706 PointsYou might also be interested in a different take on JS, rather than a Java mindset:
http://javascript.crockford.com/inheritance.html
https://medium.com/javascript-scene/the-two-pillars-of-javascript-ee6f3281e7f3#.ic9j8sl56
jesdavpet
21,489 PointsAgreed Joshua, great point!
When I started to dive deeper into the JavaScript language, I realized that applying the "Java mindset" wasn't doing me any favors. Classes are actually a topic of heated debate in the JavaScript community right now; some are against Classes being in the latest ECMAScript spec at all.
Prototypal inheritance, has a lot of advantages over Class-based inheritance in JavaScript. Although it might seem like a small difference at first glance, it's actually pretty huge.