function YalcoChicken (name, no) {
this.name = name;
this.no = no;
this.introduce = function () {
return `안녕하세요, ${this.no}호 ${this.name}점입니다!`;
}
}
function createYalcoChicken (name, no) {
return {
name, no,
introduce () {
return `안녕하세요, ${this.no}호 ${this.name}점입니다!`;
}
}
}
// 객체 리터럴
const chain1 = {
name: '판교', no: 3,
introduce: function () {
return `안녕하세요, ${this.no}호 ${this.name}점입니다!`;
}
};
// 객체 반환 함수
const chain2 = createYalcoChicken('강남', 17);
// 생성자 함수
const chain3 = new YalcoChicken('제주', 24);
console.log(chain1, chain1 instanceof YalcoChicken);
console.log(chain2, chain2 instanceof YalcoChicken);
console.log(chain3, chain3 instanceof YalcoChicken);
댓글 영역