Object.create()

PHOTO EMBED

Sat Feb 26 2022 03:04:30 GMT+0000 (UTC)

Saved by @mboljar

var personActions = {
  getFullName() {
    return this.firstName + ' ' + this.lastName;
  },
};

function createPerson(firstName, lastName) {
  let person = Object.create(personActions);
  person.firstName = firstName;
  person.lastName = lastName;
  return person;
}
Code language: JavaScript (javascript)
content_copyCOPY

https://www.javascripttutorial.net/javascript-factory-functions/