构造函数内部的方法与构造函数外部的方法有什么区别?

时间:2018-12-10 14:47:42

标签: javascript object

class User {
  constructor(firstName, lastName, age, eyeColor) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.age = age;
    this.eyeColor = eyeColor;
    this.changeName = function(name) {
      this.lastName = name;
    };
  }

  login() {
    console.log(this.firstName, "just logged in");

  }

}


var user1 = new User("james", "morrison", 23, "blue");
user1.login();

我在构造函数中有changeName方法,此方法和login方法有什么区别?

0 个答案:

没有答案