Skip to content

Feat/lyw this binding 01 - #2

Open
lywoo00 wants to merge 3 commits into
mainfrom
feat/lyw-this-binding-01
Open

Feat/lyw this binding 01#2
lywoo00 wants to merge 3 commits into
mainfrom
feat/lyw-this-binding-01

Conversation

@lywoo00

@lywoo00 lywoo00 commented Dec 9, 2025

Copy link
Copy Markdown

Summary by CodeRabbit

  • Chores
    • JavaScript의 this 바인딩 동작을 설명하는 개발자 학습 자료가 업데이트되었습니다. 새로운 예제가 추가되어 화살표 함수, 일반 함수 호출, bind를 통한 컨텍스트 유지 등 비동기 콜백에서의 this 동작 차이를 시연합니다.
    • 중복되거나 불필요한 예제는 정리(제거)되어 자료가 간결해졌습니다.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 9, 2025

Copy link
Copy Markdown

Walkthrough

this-binding 디렉토리에서 기존 한국어 예제 파일(01_박유진.js)이 삭제되고, 동일한 주제(자바스크립트 this 바인딩)를 다루는 새로운 영어 예제 파일(01_lyw.js)이 추가되었습니다. 새 파일은 여러 비동기 콜백 상황에서의 this 동작을 시연합니다.

Changes

Cohort / File(s) 변경 요약
예제 파일 삭제
this-binding/01_박유진.js
파일 삭제: 기존 this 바인딩 데모(전역 변수, 사용자 객체 및 getNameLater1~4 등) 제거
새 예제 파일 추가
this-binding/01_lyw.js
파일 추가: getName, getNameLater1 ~ getNameLater4 구현으로 정규 함수, 화살표 함수, 함수 참조, bind()에 따른 this 바인딩 차이 시연 및 호출 예제 포함

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 분

  • 변경은 파일의 교체(삭제 + 추가)로 로직 복잡도 낮음
  • 교육용 단일 예제 파일이므로 검토 항목이 제한적
  • 주의할 점: 새 파일의 비동기 콘텍스트 출력(전역 vs 객체) 확인

Poem

🐰 오래된 예제 지우고 새로 땅을 파네,
화살표는 가만히, 함수는 바람 따라가네,
bind는 가교 되어 이름을 지켜주고,
비동기 숲 속에선 누가 주인일까? 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Pull request 제목이 주요 변경사항과 관련이 있습니다. 'Feat/lyw this binding 01'은 새로운 JavaScript 파일이 this 바인딩을 설명하는 내용임을 명확하게 나타냅니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/lyw-this-binding-01

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53b569e and 5daa8ec.

📒 Files selected for processing (1)
  • this-binding/01_lyw.js (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14939bc and 53b569e.

📒 Files selected for processing (2)
  • this-binding/01_lyw.js (1 hunks)
  • this-binding/01_박유진.js (0 hunks)
💤 Files with no reviewable changes (1)
  • this-binding/01_박유진.js

Comment thread this-binding/01_lyw.js
Comment on lines +16 to +20
getNameLater2() {
console.log(this) // this는 함수를 호출한 객체를 바인딩 -> user.getNameLater1() user가 호출 했기때문에 user를 바인딩함
setTimeout(() => {
console.log("2:", this.name); // 화살표함수는 화살표 함수를 감싸고 있는 스코프의 this를 가져옴 -> getNameLater2가 감싸고있는데 getNameLater2 의 this는 user임
}, 0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

getNameLater2 주석의 메서드명 오기 및 출력 라인 수 혼동 가능성

  • Line 17 주석에서 user.getNameLater1()이라고 되어 있는데, 실제로는 getNameLater2를 설명하는 부분이라 혼동 여지가 있습니다.
  • 또한 console.log(this) 때문에 실제 콘솔에는 객체 로그 1줄 + "2: Yujin" 1줄, 총 2줄이 찍힙니다. 맨 위 문제 설명은 “정답은 4줄로 적어주세요.”라고 되어 있어서, 학습자 입장에서는 어떤 4줄을 정답으로 봐야 하는지 헷갈릴 수 있습니다.

주석과 의도를 맞추려면 최소한 메서드명을 고쳐 주는 게 좋겠습니다:

-    console.log(this) // this는 함수를 호출한 객체를 바인딩 -> user.getNameLater1() user가 호출 했기때문에 user를 바인딩함
+    console.log(this) // this는 함수를 호출한 객체를 바인딩 -> user.getNameLater2()에서 user가 호출했기 때문에 user를 바인딩함

추가로, 객체를 찍는 이 로그를 “정답에 포함하지 않아도 된다”는 식으로 한 줄 주석을 더 달아 두면 문제 풀이 입장에서 더 명확할 것 같습니다.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
getNameLater2() {
console.log(this) // this는 함수를 호출한 객체를 바인딩 -> user.getNameLater1() user가 호출 했기때문에 user를 바인딩함
setTimeout(() => {
console.log("2:", this.name); // 화살표함수는 화살표 함수를 감싸고 있는 스코프의 this를 가져옴 -> getNameLater2가 감싸고있는데 getNameLater2 의 this는 user임
}, 0);
getNameLater2() {
console.log(this) // this는 함수를 호출한 객체를 바인딩 -> user.getNameLater2()에서 user가 호출했기 때문에 user를 바인딩함
setTimeout(() => {
console.log("2:", this.name); // 화살표함수는 화살표 함수를 감싸고 있는 스코프의 this를 가져옴 -> getNameLater2가 감싸고있는데 getNameLater2 의 this는 user임
}, 0);
🤖 Prompt for AI Agents
this-binding/01_lyw.js around lines 16 to 20: the inline comment on line 17
incorrectly references getNameLater1 and may confuse readers; also the
console.log(this) prints an extra object line that learners might mistake as
part of the expected answer. Update the comment to refer to getNameLater2,
clarify that console.log(this) prints the object (one line) which can be ignored
for the "answer lines" count, and add a short one-line comment stating the
object log is not part of the expected output so the total answer lines remain
unambiguous.

Comment thread this-binding/01_lyw.js
Comment on lines +22 to +29
getNameLater3() {
const fn = this.getName;
setTimeout(fn, 0); // setTimeout은 window객체 바인딩
},
getNameLater4() {
const fn = this.getName.bind(this); // this에 강제로 user를 바인딩
setTimeout(fn, 0);
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

getNameLater3/4에서 실제로는 아무 것도 출력되지 않는 논리 오류

현재 구현에서는:

getNameLater3() {
  const fn = this.getName;
  setTimeout(fn, 0);
},
getNameLater4() {
  const fn = this.getName.bind(this);
  setTimeout(fn, 0);
},
  • getName은 문자열을 반환하지만, 그 반환값을 어디에서도 console.log로 찍지 않으므로 콘솔에는 어떤 값도 출력되지 않습니다.
  • 그럼에도 아래에서 user.getNameLater3(); //Glrobal, user.getNameLater4(); //YujinYujin처럼 주석으로 예상 결과를 적어 두어서, 실제 동작과 문제 설명이 어긋난 상태입니다.

문제 설명대로 “출력 결과 4줄”을 만들려면, getNameLater3/4에서도 반환값을 console.log로 출력해 주어야 합니다. 예를 들면 다음과 같이 수정할 수 있습니다:

  getNameLater3() {
    const fn = this.getName;
-    setTimeout(fn, 0); // setTimeout은 window객체 바인딩
+    setTimeout(() => {
+      console.log("3:", fn());
+    }, 0); // fn은 일반 함수로 호출되기 때문에 this가 Global(또는 전역 객체)로 바인딩됨
  },
  getNameLater4() {
-    const fn = this.getName.bind(this); // this에 강제로 user를 바인딩 
-    setTimeout(fn, 0);
+    const fn = this.getName.bind(this); // this에 강제로 user를 바인딩 
+    setTimeout(() => {
+      console.log("4:", fn());
+    }, 0);
  },

이렇게 하면:

  • 3번: 바운드되지 않은 fn()이 호출되어 this가 전역 객체가 되고 "3: Global"이 찍힘
  • 4번: bind(this)로 미리 바운드된 fn()이 호출되어 "4: Yujin"이 찍힘

으로, 의도한 this 바인딩 차이를 콘솔 출력만 보고도 명확히 비교할 수 있습니다.

🤖 Prompt for AI Agents
this-binding/01_lyw.js around lines 22-29: getNameLater3 and getNameLater4 call
setTimeout(fn, 0) but never log the return value of getName, so console output
comments are misleading; fix by ensuring the return of getName is logged inside
the timeout — e.g., capture fn (unbound for 3, bound to this for 4) and call
console.log on its return within the setTimeout callback (setTimeout(() =>
console.log(fn()), 0)), so the actual values appear in the console and match the
comments.

Comment thread this-binding/01_lyw.js Outdated
Comment on lines +32 to +35
user.getNameLater1(); //Glrobal
user.getNameLater2(); //Yujin
user.getNameLater3(); //Glrobal
user.getNameLater4(); //YujinYujin

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

마지막 호출부 주석의 오타 및 실제 출력과의 불일치

현재 호출부는 다음과 같습니다:

user.getNameLater1(); //Glrobal
user.getNameLater2(); //Yujin
user.getNameLater3(); //Glrobal
user.getNameLater4(); //YujinYujin

문제점:

  • Glrobal 오타가 두 번 있습니다.
  • YujinYujin처럼 이름이 두 번 반복되어 있는데, 코드 상으로는 Yujin 한 번만 출력되는 게 자연스러워 보입니다.
  • 위에서 제안한 getNameLater3/4 수정까지 반영하면, 실제 콘솔에는 "1: Global", "2: Yujin", "3: Global", "4: Yujin"처럼 prefix까지 포함된 문자열이 찍히게 됩니다.

예상 출력과 주석을 맞추려면 다음 정도로 정리하는 것을 제안드립니다:

-user.getNameLater1(); //Glrobal
-user.getNameLater2(); //Yujin
-user.getNameLater3(); //Glrobal
-user.getNameLater4(); //YujinYujin
+user.getNameLater1(); // 1: Global
+user.getNameLater2(); // 2: Yujin
+user.getNameLater3(); // 3: Global
+user.getNameLater4(); // 4: Yujin

이렇게 하면 학습자가 “정답 4줄”을 적을 때도 주석과 실제 출력이 자연스럽게 일치합니다.

🤖 Prompt for AI Agents
In this-binding/01_lyw.js around lines 32-35 the inline comments for the four
calls are wrong: they contain a repeated typo "Glrobal", an incorrect doubled
"YujinYujin", and they don’t include the actual "n: " prefixes that the
functions print; update the four comments to exactly match runtime output after
the earlier fixes so they read: //1: Global, //2: Yujin, //3: Global, //4: Yujin
(one comment per call) so comments and actual console output are consistent.

@yujinimda yujinimda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굿 잘했어요

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants