티스토리 뷰

JavaScript

'This' in JavaScript

seoca 2019. 8. 27. 03:47

 

JavaScript에서 this 키워드는 다른 언어에서의 this와 좀 다른 특징을 가지고 있다.

Java에서는 자기자신을 나타내는 용도로 사용되기에 parameter와 속성의 이름이 같을 경우나 다른 overloading된 constructor를 불러올때 사용되는데 반해 JavaScript에서는 호출하는 방법 즉, '호출한 객체' 가 누구(무엇)냐에 따라 this가 달라진다.

 

bind() method를 사용해 this를 고정시키는 방법도 있다. 

 

 

Reference

https://www.youtube.com/watch?v=PAr92molMHU

'JavaScript' 카테고리의 다른 글

Callback function in JavaScript  (0) 2019.08.28
Arrow function in JavaScript  (0) 2019.08.28
Closure in JavaScript  (0) 2019.08.27
Creating Object and document.write in JavaScript  (0) 2019.08.07
String and Number  (0) 2019.08.05