Day 36

in code •  7 years ago 

February 18th 2018

Hello! At the ES6 course by Wes Bos I learned about classes. Before classes we used prototype inheritance, which when you put a method on the original constructor.

     function Dog(name, breed) {
         this.name = name;
         this.breed = breed;
     }

 Dog.prototype.bark = function() {
        console.log(`Bark Bark! My name is ${this.name}`)
 }

If you write just snickers in the console you won't get the prototype.bark or snuggle because they are only instances of the prototype. But if you open the object they are there.

Two ways to make classes in ES.
Class declaration and class expression, two ways of making a Class.

Declaration class Dog {}
Expression const Dog = {}

  class Dog {
        constructor(name, breed) {
            this.name = name;
            this.breed = breed;
      }

   bark() {
        console.log(`Bark Bark! My name is ${this.name}`);
 }

extends a Class

 class Dog extends Animal {
      constructor(name, breed) {
      super(name);
      this.breed = breed;
    }

name is already defined in an 'Animal' class.
Cheers!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

nice writing, breed! breed!! breed!!!

Thanks! Breedisgood!