I want to add multiple properties to "Person" class. This instance will be called by getDetails() method. So I easily can pass an array of values to my objects (variable), ex. var john = new Person("John Doe", "32", "Web Developer");.
function Person(name, age, occupation) {
this.name = name;
this.age = age;
this.occupation = occupation;
}
Person.prototype.getDetails = function () {
return this.name;
return this.age;
return this.occupation;
};
var john = new Person("John Doe", "32", "Web Developer");
document
.getElementById('demo')
.innerText = john.getDetails();
<h2>JavaScript Class Method</h2>
<p>How to define and use a Class method.</p>
<p id="demo"></p>
console.log(john)and you will see that too. The way you are inspecting your data is incorrect. Since a function can onlyreturnonce, anything afterreturn this.name;is ignored.