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

this #5

Open
DeanTG opened this issue Feb 1, 2023 · 2 comments
Open

this #5

DeanTG opened this issue Feb 1, 2023 · 2 comments

Comments

@DeanTG
Copy link
Owner

DeanTG commented Feb 1, 2023

link

@DeanTG
Copy link
Owner Author

DeanTG commented Feb 1, 2023

在函数中this到底取何值,是在函数真正被调用执行的时候确定的,函数定义的时候确定不了

@DeanTG
Copy link
Owner Author

DeanTG commented Feb 1, 2023

  1. 构造函数:函数作为构造函数用,那么其中的this就代表它即将new出来的对象。
  2. 对象属性:如果函数作为对象的一个属性时,并且作为对象的一个属性被调用时,函数中的this指向该对象。
  3. call或者apply调用:当一个函数被call和apply调用时,this的值就取传入的对象的值。
  4. 全局 & 调用普通函数:在全局环境下,this永远是window;普通函数在调用时,其中的this也都是window。

image

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

No branches or pull requests

1 participant