Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23장] 실행컨텍스트_신준혁 #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oridori2705
Copy link
Collaborator

✅ 학습 내용 요약

  • 실행 컨텍스트

🤔 궁금했던 부분

1. 일반함수의 this와 생성자 함수의 this 차이는??

this를 사용하고 있는 함수가 어떻게 호출된 함수냐에 따라 달라진다.

일반함수의 this
=> 전역 객체

// 전역 함수
function testFunc1 () {
  console.log(this) // Window
}

메소드함수에서의 this
=> 해당 메소드를 가지고 있는 객체를 가리킨다.

const testObj = {
  // 메소드
  foo: function () {
    console.log(this) // testObj
    // 내부 함수
    function bar () {
      console.log(this) // Window
    }
  }
}

생성자함수에서의 this
-함수를 호출할 때 new를 붙여서 호출하면 해당 함수는 생성자로서 동작한다.

  • this는 내부 객체를 가리킨다.
function User (name, id) {
  this.name = name
  this.id = id
}

// 생성자로서 호출
const user1 = new User('Jay', 'jay01')
console.log(user1) // User

// 일반 함수로서 호출
const user2 = User('Mac', 'mac01')
console.log(user2) // undefined
console.log(window.name) // 'Mac'

2. 전역 렉시컬 환경은 객체환경레코드와 선언적 환경 레코드로 구성되어있고, 함수 렉시컬 환경은 함수 환경 레코드로만 구성되어있는 것인가?

전역 렉시컬 환경의 구성 컴포넌트와 함수환경 레코드의 구성 컴포넌트가 다른 것이 맞는지 궁금하다!

3. [[GlobalThisValue]] 와 [[ThisValue]]로 구분한 이유는 전역과 함수의 차이인가?

4. 책에서 의미하는 [[Environment]]란 외부 렉시컬 환경에대한 참조와 동일한 것인가?

@oridori2705 oridori2705 self-assigned this Nov 4, 2023
@yougyung
Copy link
Member

yougyung commented Nov 4, 2023

엄청 빨리 작성하셨네요 👍 저도 분발해서 실행컨텍스트 읽으러갑니다

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