Method source code in OOP in JavaScript
You can get the source code of a class method if you access it without parentheses. Let's try. Let's say we have the following class:
class User {
#name;
constructor(name) {
this.#name = name;
}
getName() {
return this.#name;
}
}
Let's create an object of this class:
let user = new User('john');
Let's output the source code of the method:
console.log(user.getName);
Print the source code of some method of class Employee.