Classes in Vanilla Javascript

January 05, 2019

Constructor:

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

Class Methods:

Dog.prototype.greet = function() {
    return this.name + " says hello.";
}

Test the class:

const myDog = new Dog("Captain Morgan", 5);
console.log(myDog.greet());