프로그래밍/JavaScript
JavaScript 객체 그리고 this
choi_9182
2020. 3. 11. 10:41
# 객체 생성과 호출의 예제
// #1
var person = {}; // [object Object] 이런 결과를 볼 수 있다.
// #2
var person = {
name : {
first: 'Bob',
last: 'Smith'
},
age : 32,
gender : 'male',
interests : ['music', 'skiing'],
greeting: function() {
alert('Hi! I\'m ' + this.name.first + '.');
}
};
// 방식 2가지 중 첫 번째
person.name.first
person.age
// 두 번째 ( 괄호표기법 )
person['name']['first']
person['age']
pesron:greeting()
# this 는 현재 실행 문맥이다.