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

taro3 this指向似乎和react不同 #8183

Closed
gjc9620 opened this issue Dec 2, 2020 · 4 comments
Closed

taro3 this指向似乎和react不同 #8183

gjc9620 opened this issue Dec 2, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@gjc9620
Copy link

gjc9620 commented Dec 2, 2020

这个特性解决了什么问题?

讨论

taro3 
class A  {
  c(){
    this //View node?
  },
  render(){
    return (
      <View onClick={this.c}>
    )
  }
}

请问为什么这里的this是 View 看起来和react不一样

也许是this应该是A比较合理吗? 和react一致

@taro-bot2 taro-bot2 bot added the enhancement New feature or request label Dec 2, 2020
@jenerse
Copy link

jenerse commented Dec 3, 2020

你需要bind(this)才会指向A。或者 onClick={() => this.c()}

@gjc9620
Copy link
Author

gjc9620 commented Dec 3, 2020

你需要bind(this)才会指向A。或者 onClick={() => this.c()}

解决这个问题非常简单
其实我想了解为什么这样设计 以及能不能判断内置组建的时候 把this改过去
毕竟react 在div的onclick this不会是 div

@Chen-jj
Copy link
Contributor

Chen-jj commented Dec 4, 2020

要指向 A 就需要 bind,不 bind 时指向什么不太重要吧。

@Chen-jj Chen-jj closed this as completed Dec 4, 2020
@gjc9620
Copy link
Author

gjc9620 commented Dec 4, 2020

要指向 A 就需要 bind,不 bind 时指向什么不太重要吧。

为什么不bind的时候 指向view呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants