1.function
function Person(name) { this.name = name; } Person.prototype.getName = function () { return this.name; }; var john = new Person("John Doe"); console.log(john.getName());
2.class
class Person { constructor(name) { this.name = name; } getName() { return this.name; } }