Override Inherited Methods Question

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?

1 Like

I’m not exactly sure what you’re asking. You aren’t updating the prototype here. The prototype is unchanged. You are updating the speak() function for a single instance of a User object.

1 Like