create object from another object javascript code example
Example 1: create nodejs new object
const personFactory = (firstName, lastName, email) => {
return {
firstName: firstName,
lastName: lastName,
email: email,
info() {
return `${this.firstName} ${this.lastName}, ${this.email}`;
}
};
};
let person = personFactory('John', 'Doe', '[email protected]');
console.log(person.info());
Example 2: create nodejs new object
function Person(fname, lname) {
this.firstName = fname;
this.lastName = lname;
}