반응형
<button>버튼</button>
<script>
const btn = document.querySelector("button");
btn.addEventListener("click", () => {
this.open(); // 여기서 this는 window 객체를 가리킴
});
</script>
const person1 = {
age: 10,
grow: function() {
this.age++;
console.log(this.age);
}
};
person1.grow();
const person2 = {
age: 10,
grow: () => {
this.age++;
console.log(this.age);
}
};
person2.grow();
평소 화살표 함수는 잘 안 썼는데 딥다이브 보다가 발견해서 기록해둠.
그런데 화살표 함수가 어느 경우에나 유용하진 않아서 경우에 따라 사용하면 되는데 참고1을 보면 될 듯.
참고2: https://www.w3schools.com/js/js_window.asp
JavaScript Window
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
www.w3schools.com
반응형
'JS, jQuery' 카테고리의 다른 글
자바스크립트 Element 객체 가져오기 (0) | 2023.05.26 |
---|---|
js - 특정 엘리먼트로 이동하는 2가지 방법 (0) | 2023.05.25 |
스크롤 메뉴(Scroll Menu) 구현해보기 (0) | 2023.05.22 |
[jquery] each 메서드 (0) | 2023.05.22 |
jquery val(); (0) | 2023.05.22 |