javascript 생성자 함수(prototype)
const heropy = {
firsName: 'Heropy',
lastName: 'Park',
getFullName: function () {
return `${this.firsName} ${this.lastName}`
}
}
console.log(heropy.getFullName());
const amy = {
firstName: 'Amy',
lastName: 'Clarke',
getFullName: function () {
return `${this.firstName} ${this.lastName}`
}
}
console.log(amy.getFullName())
const neo = {
firstName: 'Neo',
lastName: 'Smith',
getFullName: function () {
return `${this.firstName} ${this.lastName}`
}
}
console.log(neo.getFullName())
function User(first, last) {
this.firstName = first
this.lastName = last
}
User.prototype.getFullName = function () {
return `${this.firstName} ${this.lastName}`
}
const heropy = new User('Heropy', 'Park')
const amy = new User('Amy', 'Clarke')
const neo = new User('Neo', 'Smith')
console.log(heropy.getFullName())
console.log(amy.getFullName())
console.log(neo.getFullName())