[JavaScript] 예시를 통해 알아보는 this
2022. 12. 28. 14:46
프로그래밍 언어/JavaScript
JavaScript에서 this 는 함수 호출 방법에 의해 결정된다. 예시1) 객체 메소드의 this const phone = { name: 'Galaxy Note 3', getName: function () { console.log("getName: ", this); }, } phone.getName(); // output: getName: {name: 'Galaxy Note 3', getName: f} getName 메소드의 호출자가 phone 객체이므로, getName 실행 시 this 는 phone 객체이다. 예시2) 전역 객체에서의 this const phone = { name: 'Galaxy Note 3', getName: function () { console.log("getName: ", ..