Is it possible to use prototypes to add a function for a class instance?
allowing me to access this
or __proto__
keyword inside my method, like so:
class PersonClass {
name: string;
constructor(name: string) {
this.name = name;
}
sayHello() {
console.log(`hello, my name is ${this.name} and I'm a ${this.type}`);
}
}
PersonClass.prototype.type = "human";
PersonClass.prototype.PrintType = () => {
console.log(`I'm a ${PersonClass.prototype.type}`);
};
const aria = new PersonClass("Ned Stark");
aria.sayHello();
aria.PrintType();
This code works as expected, but I want to add something like
PersonClass.prototype.SayHello2 = () => {
console.log(this.name, caller.__proto__.name);
};
which currently does not work.
Is there a way to achieve this?