We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
const a=()=>{ console.log(this) } const obj={ a:1, fn(){ const arrow=()=>{ console.log(this.a) } } } obj.fn() // 1
转义后(spec:true):
spec:true
"use strict"; var _this = void 0; function _newArrowCheck(innerThis, boundThis) { if (innerThis !== boundThis) { throw new TypeError("Cannot instantiate an arrow function"); } } var a = function a() { // 检查this,也就是为什么箭头函数不能new _newArrowCheck(this, _this); console.log(this); }.bind(void 0); var obj = { a: 1, fn: function fn() { var _this2 = this; var arrow = function arrow() { _newArrowCheck(this, _this2); console.log(this.a); }.bind(this); } }; obj.fn(); // 1
var xx=function xx(){}
_this
_newArrowCheck
this
new
The text was updated successfully, but these errors were encountered:
No branches or pull requests
箭头函数
转义后(
spec:true
):var xx=function xx(){}
形式,同时在函数外层创建_this
并在函数内使用;无法变量提升。_newArrowCheck
检查是this
是否相同,被new
时报错。The text was updated successfully, but these errors were encountered: