In this video, I discuss the concept of inheritance in Object-Oriented Programming (OOP) with JavaScript and using ES6 classes.
🎥Classes (JS): https://youtu.be/T-HGdc8L-7w
🎥Polymorphism (JS): https://youtu.be/8a5BkwuZRK0
🎥Encapsulation (Java) : https://youtu.be/YcbcfkLzgvs
🎥Inheritance (Java) : https://youtu.be/e6eXD8DHc_A
🎥Polymorphism (Java): https://youtu.be/qqYOYIVrso0
🚂 Website: http://thecodingtrain.com/
💖 Patreon: https://patreon.com/codingtrain
🛒 Store: https://www.designbyhumans.com/shop/codingtrain/
📚 Books: https://www.amazon.com/shop/thecodingtrain
🎥 Coding Challenges: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
🎥 Intro to Programming: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
🔗 p5.js: https://p5js.org
🔗 Processing: https://processing.org
📄 Code of Conduct: https://github.com/CodingTrain/Code-of-Conduct
Original source
49 responses to “16.17: Inheritance in JavaScript – Topics of JavaScript/ES6”
Love the video! Just one thing:
Make sure to clarify that the ES6 classes are still using the same prototypal inheritance as normal JS, and shouldn't be confused with the way inheritance works in languages like C++ and Java. (only the syntax is similar)
The prototype chain and the quirks of the "this" context are all still present. The syntax for classes in ES6 hides this fact and can cause a lot of confusing errors.
Hope this makes sense.
I tried to talk to my dad about inheritance. He didn't want to discuss it.
Great video. You are amazing man .
You are just awesome!!!
Inheritance starts at 7:20
Can you have more than one inheritance? For instance class Confetti extends particle extends circle ?
I miss my Bubble… 🙁
Perfect tutor ever😂
javascript is copying so much from java, might as well use java and not use javascript anymore.
He has the all-new ways to learn code, cheers!
Your videos are the best. I am smiling while learning and watching a js tutorial.
I always hope that someday I could take my skills and become a teacher to the next generation of programmers and I strive to be as good a teacher as you!
It feels sooo good to understand something like this! Thank you sir!
Nice video, helped me. I'm doing web-components now in my comp sci class
nice shirt man, where did u buy it?
I’m curious you said that a class can only inherit one other class, do you mean for example I couldn’t say “class Bat extends mammal, bird” to for example get the mammal class and as well pull flight from the bird class? I hope that makes sense. Thank you.
Are u gay ?? ahahahahaha
your tuts are the gold standard here on yt
Wow, you are awesome. Really great explanation.
I don't wish to be rude, but you don't explain things well for a beginner.
dude you're awesome
I wanted the code from this video. does someone knows how can I get that ?
You are my new favorite teacher. I hope you'll decide to start teaching full JavaScript courses and sell them at Udemy or something.
I'm one of the people that's beeen watching you from the future. So had the opportunity to notice your hair styles evolution …. from happy relaxed to happy "businessman" style. So is this latest style just temp?
Is Nodes implementation of JS different? This doesn't work for me – the super(x,y) is not a valid keyword. Regardless, great video. You're the man! 🙂
Hi,
I would like to know, what is the difference between Class-Inheritance and Object-inheritance.
Thank you.
WHAT IS TO BE A BUBBLE???!!!
SENSEIIII!!
Thank you,
May you explain what difference between abstraction and encapsulation?
Really appreciate your videos! Learned a lot from you
I wish all videos about JS were the same expressive and enthralling as yours. 🙂 Many thanks for your work!
VS Code <3 😛
You should go over getters and setters. Factory functions would be great too
could you use the super keyword for the show function for example
show(){
super.show()
fill(this.bright)
square(this.x, this.y, this.r)
}
or would it cause errors or would it just draw it as a circle .
edit: I will be trying this myself and will comment what happens but wanted to comment in-case I forget
happy to see concepts as such explained.
What is that editor name..
Where is the video about encapsulation in ES6?
I finally realized that you have to be a good programmer to code in JavaScript
When I was learning Java, Interitance was something that took me a while to get my head around. I wish I had this video when I was learning this. You've made this way more clear than anyone else. Thanks Daniel.
Hello sir, can you add index. Html page, I need to see the code
i wish i could type fast like you do
Your dedication to educating about JS is impressive. I hope this channel pays of for you in the end even if that is not the goal.
Honestly, these videos are so wholesome, I never thought the day would come where I'm gonna watch OOP explanation videos on YouTube just to brighten up my day, but here we are.
As a JS developer I can say that composition is preferred over inheritance. Please do a video about it, people will love it 😀
Your hand drawn curly braces are outrageous! 😉
composition over inheritance! just saying. 🙂
So to create the Tree, you would for example (in place of Particle class) have Animal class and then the (in place of Confetti class) have 'class Mammal extends Animal'? To do the tree would the next just be for example 'class Four legs extends Mammal' or 'class Four legs extends Animal'? Does the new class become the new super class?
Are you going to make videos on polymorphism and encapsulation? And if you already did, where can I find those videos?
do you really need different classes to work with? and is it really bad to have conditionals within the class? example I have BigDataGrid class, do I really need to create separate DataGrid for each report? it seems highly maintainable in the future but highly quite alot to type with. anyway, thanks for the idea.
If you need a nice example here you go. Change classes using SPACE, hold Mouse1 to draw:
let interval = 0, id = 0, objects = [], classes = [];
function setup()
{
createCanvas(500, 500);
//frameRate(60);
}
function draw()
{
background(255);
objects.forEach(p => {
p.update();
p.render();
});
if(mouseIsPressed)
if(!(++interval % 5))
objects.unshift(new classes[id%3](mouseX, mouseY, 20));
}
function keyPressed()
{
if(keyCode == 32) id++;
}
class Particle
{
constructor(x, y, r)
{
this.x = x;
this.y = y;
this.r = r;
}
update()
{
this.x += random(-2, 2);
this.y += random(-2, 2);
}
render()
{
ellipse(this.x, this.y, this.r);
}
}
classes[0] =
class Square extends Particle
{
constructor(x, y, r)
{
super(x, y, r);
this.t = millis();
}
render(){
let s = sin((millis() – this.t)/100)*10
rect(this.x, this.y, this.r + s, this.r + s);
}
}
classes[1] =
class Circle extends Particle
{
update()
{
super.update();
this.r = sin(millis()/500) * 10
}
render(){
ellipse(this.x, this.y, this.r);
}
}
classes[2] =
class Line extends Particle
{
update(){
this.x += 1;
}
render(){
line(this.x, this.y, this.x + this.r, this.y);
}
}
Thank you Daniel! It was really useful stream, I learned a lot, so it's all makes sense now, how to write less code and organize a project. Hope you continue with Polymorphism in the next video.