Property와 Method로 이루어진 각 객체들의 상호작용을 중심으로 코드를 작성하는 것
function createUser(name, email){
const user = {
name,
email,
print(){
console.log(`${this.name}의 이메일은 ${this.email} 입니다.`);
}
}
return user;
}
const user1 = createUser('해리', 'harry@hogwarts.com');
user1.print();
function User (name, email){
this.name = name;
this.email = email;
this.print = ()=>{
console.log(`${this.name}의 이메일은 ${this.email} 입니다.`);
}
}
const user1 = new User('해리', 'harry@hogwarts.com');
user1.print();
class User {
constructor(name, email){
this.email = email;
this.name = name;
}
print(){
console.log(`${this.name}의 이메일은 ${this.email} 입니다.`);
}
}
const user1 = new User('해리', 'harry@hogwarts.com');
user1.print();