const audio = {
title: 'a',
// 메서드
play() {
console.log('paly this', this);
}
}
// 실행
audio.play();

audio.stop = function() {
console.log('stop this', this);
}
audio.stop();
function playAudio() {
console.log(this);
}
playAudio();

객체를 만들기 위해 사용하는 함수,
new키워드와 함께 쓰임
이름 대문자로 시작
👉 "이건 생성자야" 라는 의미로 구분하기 쉽게 하기 위한 관례
function Audio(title) {
this.title = title;
console.log(this);
}
const audioA = new Audio('a');

function Audio(title) {
// this.title = title;
console.log(this);
}
const audioA = new Audio('a');

const audio = {
title: 'audio',
categories: ['rock', 'pop', 'hiphop'],
displayCategories() {
this.categories.forEach(function(category) {
console.log(`title: ${this.title},
category: ${category}`);
})
}
}
audio.dispalyCategories();





const audio = {
title: 'audio',
categories: ['rock', 'pop', 'hiphop'],
dispalyCategories() {
// 콜백함수에서 화살표함수로 변경
this.categories.forEach((category) => {
console.log(this);
})
}
}
audio.displayCategories();

