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方法有什么区别?