Skip to content
Advertisement

can I add non static method to external class using prototypes?

Can I add using prototypes function for a class instance?

so I’ll be able to use this or __proto__ keyword inside my method, for example:

JavaScript

this code works of course, but I wish to add something like

JavaScript

which of course fails.

is it even possible?

Advertisement

Answer

Your SayHello2 should be a non-arrow function to access the properties you are looking for:

JavaScript

which produces:

JavaScript

Don’t forget you also have access to the constructor property of an instance as well, allowing you to access everything associate with your classes.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement