const sonata = {
name: '소나타',
color: '흰색',
speed: 0,
speedUp: function(speed) {
this.speed += speed;
},
speedDown: function(speed) {
this.speed -= speed;
},
show: function() {
document.write('차량명 : ' + this.name + '<br>');
document.write('차량색 : ' + this.color + '<br>');
document.write('차량속도 : ' + this.speed + '<br>');
}
};
sonata.speedUp(80);
sonata.speedDown(20);
sonata.show();
const { name, color, speed } = sonata;
document.write(name + ', ' + color + ', ' + speed);
JavaScript에서 제공하는 **기본 객체(내장 객체)**는 프로그램 개발에 매우 유용한 기능 제공
| 객체 | 주요 메서드 | 설명 |
|---|---|---|
| Array | forEach(), map(), filter() |
배열 반복 처리 및 새로운 배열 생성 |
| String | charAt(), indexOf(), substring() |
문자열 처리 |
| RegExp | test(), match() |
정규 표현식 사용 |
| Math | ceil(), random() |
수학 연산 |
| Date | getYear(), getMonth(), getDate() |
날짜/시간 정보 조회 |