moringaman
3/28/2017 - 11:49 PM

Adding new objects or functions to constructor functions

Adding new objects or functions to constructor functions

function Person (firstname, lastname) {
  this.firstname = firstname
  this.lastname = lastname
}

Person.prototype.getFullName = function () {
  return this.firstname + ' ' + this.lastname
}

var john = new Person('John', 'Doe')
var jane = new Person('Jane', 'Doe')

console.log(john.getFullName())
console.log(jane.getFullName())