My goal is to define a class called "User" and then add a method to the class using the "prototype" keyword. I want the method "who_auto" to be accessible to all future instances of "User".
When testing this code in JSFiddle, I encountered the error message: "Uncaught TypeError: pp.who_auto is not a function"
Here's the revised code:
class User {
constructor(name) {
this.name = name;
this.chatroom = null;
}
who() {
return `I am ${this.name}`;
}
}
User.prototype = {
who_auto: function() {
console.log(`
Hello, I am ${this.name}
`);
}
}
const pp = new User('peter parker');
console.log(pp);
console.log(pp.who());
pp.who_auto();