var coworkers={
"programmer":"egoing",
"designer":"leezche"
};
document.write("programmer : "+coworkers.programmer+"<br>");
document.write("designer : "+coworkers.designer+"<br>");
//방법 1
coworkers.bookkeeper="duru";
document.write("bookkeeper : "+coworkers.bookkeeper+"<br>");
//방법 2
coworkers["data scientist"]="taeho";
document.write("data scientist : "+coworkers["data scientist"]+"<br>");
for(var key in coworkers){
document.write(key+'<br>');
}
/* 결과
programmer
designer
bookkeeper
data scientist
*/
for(var key in coworkers){
document.write(coworkers[key]+'<br>');
}
/* 결과
egoing
leezche
duru
taeho
*/
coworkers.showAll = function(){
for(var key in coworkers){
document.write(coworkers[key]+'<br>');
}
}
coworkers.showAll = function(){
for(var key in this){
document.write(coworkers[key]+'<br>');
}
}
함수 정의
방법1)function showAll(){ }
방법2)
var showAll = function(){ }
방법3)
객체명.showAll = function(){ }
var Body = {
setColor : function(color){
document.querySelector('body').style.color=color;
},
setBackgroundColor : function(color){
document.querySelector('body').style.backgroundColor=color;
}
}