강의

멘토링

커뮤니티

Inflearn Community Q&A

dbstjdgy61339's profile image
dbstjdgy61339

asked

Learn Javascript ES6+ properly - Beginner

About forEach, map, and reduce methods

궁금한게 잇는데요 여기서 this는 array값을 출력해주나요?

Written on

·

345

0

this 는 a에 array값을 가르키나요 ㅠ? 

javascriptes6

Answer 1

0

jaenam님의 프로필 이미지
jaenam
Instructor

thisArg에 지정된 대상을 가리킵니다.

const a = [1, 2, 3];
a.forEach(function(v, i, array) {
    console.log({ v, i, array, this: this });
});
// thisArg를 지정하지 않았으므로 global객체를 바라봄.

a.forEach(function(v, i, array) {
    console.log({ v, i, array, this: this });
}, [10]);
// thisArg를 [10]으로 지정하였으므로 [10]을 바라봄.
dbstjdgy61339's profile image
dbstjdgy61339

asked

Ask a question