function Animal (name, type) { this.name = name this.type = type this.age = 0 } Animal.prototype.birthday = function () { this.age++ } const leo = Animal('Leo', 'Lion')
function Animal (name, type) { this.name = name this.type = type this.age = 0 } Animal.prototype.birthday = function () { this.age++ } const leo = new Animal('Leo', 'Lion')
Inside our Animal constructor function, we’re relying on JavaScript to create a this object for us. However, in order for it to know to do that, we need to invoke the function with the new keyword.