I continually get an error on my local PC when attempting to update the prototype explicitly. However, the same language passes the FCC test for “OOP: Override Inherited Methods”.
Javascript seems very happy to do the prototype work implicitly when the prototype keyword is removed, as below:
class User {
constructor(userName, password) {
this.userName = userName;
this.password = password;
}
speak() {
return "Hello there!"
}
}
var user1 = Object.create(User.prototype);
console.log(user1.speak());
var myUser = Object.create(User.prototype);
myUser.userName = "kevin";
myUser.password = "password";
// no prototype required here
myUser.speak = function() {
return "talking...";
};
console.log(myUser.speak());
Am I doing something wrong, or is this simply ES6 syntactic sugar?