-
Notifications
You must be signed in to change notification settings - Fork 1
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 指向 #9
Labels
Comments
毫无尿点 var obj={ A.call(obj) |
还是不懂 |
毫无亮点,只是几个demo 而已,建议看《你不知道的js,上部分》 |
写的东西自己能理清逻辑想表达什么吗? |
建议看一下这里的示例
为什么 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
现在假设你已经知道以下几点:
好 知道这几点之后 我先总结下:
举几个 🌰:
上图,箭头函数的 this 指向 foo 的 this 那 foo 的 this 指向哪儿呢 看调用位置 这里指向 obj 所以箭头函数的 this 也指向 obj
2.在箭头函数出现之前 一种 hack 方法是用 self/_self/that 来绑定 this 有了箭头函数 这种写法就不需要惹:
3.由于已经按照词法作用域绑定了 再使用 call/apply/bind 传的第一个参数并不改变 this 指向 因此可忽略
所以下图中的还是 -18 :
参考资料(建议按先后顺序看)
The text was updated successfully, but these errors were encountered: