1

First Way

function User(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
}
User.prototype.login = function() {
    console.log(`${this.firstName} Logging in.....`);
}

Second Way

function User(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.login = function() {
        console.log(`${this.firstName} Logging in...`);
    }
}

Both seems to be producing the same results. Are there any situations to choose one over another?

Hein Htet Zaw
  • 13
  • 2
  • 6

0 Answers0