In JavaScript you can use the OOP (Object-Oriented-Programming) feature of “classes” to construct objects which are then useful resources for your script/application.
Learn all about classes in JavaScript in this video.
⭐️ Course Contents ⭐️
⌨️ (00:00) The Basics
⌨️ (14:40) Getters and Setters
⌨️ (22:43) Static Methods
⌨️ (30:11) Inheritance and Extends
⌨️ (40:22) Polymorphism
⌨️ (46:00) Classes in Practice
Learn more about JavaScript in this full course: https://www.youtube.com/playlist?list=PLWKjhJtqVAbk2qRZtWSzCIN38JC_NdhW5
🎥Tutorial by dcode. Check out the dcode channel for more great tutorials: https://www.youtube.com/channel/UCjX0FtIZBBVD3YoCcxnDC4g
🐦dcode on Twitter: @dcodeyt
—
Learn to code for free and get a developer job: https://www.freecodecamp.org
Read hundreds of articles on programming: https://medium.freecodecamp.org
And subscribe for new videos on technology every day: https://youtube.com/subscription_center?add_user=freecodecamp
Original source
39 responses to “JavaScript Classes Tutorial”
Head over to my channel for more JavaScript tutorials like this one 😁
Thanks a lot
I did it using this way:
class List {
constructor(_element){
this.element = _element;
}
update(){
console.log(2);
while (this.element.firstChild){
this.element.removeChild(this.element.firstChild);
console.log(1);
}
}
add(newli){
let newnode = document.createElement("li");
let text = document.createTextNode(newli);
newnode.appendChild(text);
this.element.appendChild(newnode);
}
}
God bless freeCodeCamp
You just took me too the next level. Thanks!
class Video {
constructor(title, likes) {
this.title = title;
this.likes = likes;
}
like() {
this.likes++;
}
}
let video = new Video('JavaScript Classes Tutorial', 762);
video.like();
console.log(video.likes); // 763 (awesome video!)
thank you so much…..
good video bro
sow…
First 45min are excellent as it's well explained. Last 15 min you're rushing through it and throwing in several new techniques and combing them, hence causing confusion.
I have a question. Why should i use the classes instead of using a function constructor to create a new object and assign properties and method to it
Great tutorial.
A very helpful refresher course! Thanks Dom!
the first 45 min are ok for begginers, or someone who knows somewhat. But the last 15 min you just rush thru it, it is not clear for newbies.
It took JS (and this video) to make me finally understand classes
Please upload bootstrap latest tutorial
who else loves the sound of keyboard?
Why exactly are we adding underscore before parameter name in constructor() function?
Fixed my problem with super()! Thank you!
This is great! Do not be put of by the 1 hour length. Its worth a watch!
Brother I'm getting this error.
Any help?
ListBInding.js:14 Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.
excelently explained. Thank you.
beautifully explained. I especially appreciate the fact that you show how classes can be used in real situations. Often that is missing and then the explanation will not stick. I loved it!
Nice tutorial. Is there anymore to OOP than this or is knowing this enough?
Great tutorial, excellent explanations, thanks a lot!
Thank you! Really interesting tutorial. And I got some problem in [51:33] , "while (this.listElement.firstChild) {" 👈 Here the "firstChild" property did not work for me, but when I changed it to "this.listElement.firstElementChild" it worked well. Does any one know the reason for that?
Great tutorial, the last part was especially cool! It's funny how you are referring to a DOM element as 'physical' though 🙂 but I can relate.
On 15:26 why not just say listElement.innerHTML = ""?
Useful lesson!
Is it best practice to put an '_' in front of parameters which have the same name as a property?
repeatedly calling the update method when using add() is a bit confusing. Why does it not remove the "dcode" when you add "dog"? Isn't it supposed to remove all the <li> items if there is already a firsChild <li>dcode</li>? Can you please elaborate more on this? Thank you.
Thank u for this awesome video
Super easy to understand. Thank you
the line is not correct, correct IS :
printDescription(){console.log('I am rectangle of '+ this.width +' x ' + this.height + ' and I am: ' + this.color)};
this Guy do not know what about is talking !
Thank you. I liked the video, it is good and I've learned quite a bit. Just one thing about the last example of DOM manipulation – it was a bit harder to understand, because I felt that not all was laid out in a clear and correct order, so it was a bit confusing. But still – great job, thanks again.
love FCC
thank you for this video. 🙂
Great lesson, thanks!
You earned my sub 🙂
Thank you for your effort!