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
在浏览器非严格模式下,this 指向的是 window
this
window
// 浏览器环境下 console.log('this A=====>>>', this) // {}
在块级作用域内
// 此时的this指向就是指向就是他自己 const test = { prop: 42, func: function() { // console.log('this B=====>>>', this) // { prop: 42, func: [Function: func] } return this.prop; }, };
The text was updated successfully, but these errors were encountered:
在 class 中比较特殊,两个类的继承,继承的类要使用 super()才可以访问到 this
class
super()
class A { constructor() { this.a = 'hello' this.b = 'world' } getName() { return '执念' } } class C extends A { constructor() { super() // 自动继承A类中的方法属性 this.prop = { a: 10 } } getThis() { // 这里的this指向的值当前C类 // 这里有一个点需要注意,在class的继承过程中 // 子类继承父类的时候,必须使用 super() 方法,才可以继承父类的方法和属性 // 在此之前 this 是访问不到的 console.log('class this ===>>', this) return this } } const c = new C() console.log('c.getThis()=====>>>', c.getThis()) console.log('c.getName()=====>>>', c.getName())
Sorry, something went wrong.
No branches or pull requests
在浏览器非严格模式下,
this
指向的是window
在块级作用域内
The text was updated successfully, but these errors were encountered: