Adding Methods to Constructors – Object-Oriented JavaScript


So notice back in our diagram that the object that has the dot loc property, each of these car objects in our program has not been generated from whole cloth anymore. We passed it through a decorator function. And when it came back out, it was given the dot loc property, pointing to whatever value it has. Decorators can add more than just simple properties like this number. Remember, functions are properties too. Maybe we’d prefer to call the Move Function using method calling syntax, which means we would look it up as a property of Amy before invoking it on Amy. If we want to do this, we’re going to have to re-factor our code again. So take a moment to re-factor this code in a way that would enable us to use this method calling syntax with dot access

Add a Comment

Your email address will not be published. Required fields are marked *