In many react compon著作权归作者所有,禁止商业用途转载。【原创不易,请尊重版权】ent’s construc转载请注明出处:www.tangshuang.net【访问 www.tangshuang.net 获取更多精彩内容】tor, developers alwa【版权所有】唐霜 www.tangshuang.net【本文受版权保护】ys bind its methods 【关注微信公众号:wwwtangshuangnet】【原创内容,转载请注明出处】with this, like:
未经授权,禁止复制转载。【版权所有,侵权必究】【版权所有】唐霜 www.tangshu【本文首发于唐霜的博客】【版权所有,侵权必究】ang.netexport default class MyComponent extends Component {
constructor() {
this.say = this.say.bind(this)
}
...
}
This sentence seems 【本文受版权保护】【访问 www.tangshuang.net 获取更多精彩内容】to be stupid. Is thi【转载请注明来源】【访问 www.tangshuang.net 获取更多精彩内容】s regulated by react未经授权,禁止复制转载。本文作者:唐霜,转载请注明出处。?
【关注微信公众号:wwwtangshua【未经授权禁止转载】【原创内容,转载请注明出处】ngnet】本文作者:唐霜,转载请注明出处。【本文受版权保护】No!
原创内容,盗版必究。【访问 www.tangshuang.n【本文受版权保护】【关注微信公众号:wwwtangshuangnet】et 获取更多精彩内容】转载请注明出处:www.tangshua原创内容,盗版必究。【作者:唐霜】ng.netIn fact, react compo【作者:唐霜】原创内容,盗版必究。nent class follow ES本文作者:唐霜,转载请注明出处。著作权归作者所有,禁止商业用途转载。6 class std. The rea著作权归作者所有,禁止商业用途转载。转载请注明出处:www.tangshuang.netson to put this sent本文作者:唐霜,转载请注明出处。【原创不易,请尊重版权】ence is because when原创内容,盗版必究。【未经授权禁止转载】 you use this.say in【本文受版权保护】【本文受版权保护】 your render, you al本文作者:唐霜,转载请注明出处。原创内容,盗版必究。way use it as onClic原创内容,盗版必究。【版权所有,侵权必究】k callback function,【关注微信公众号:wwwtangshuangnet】【本文首发于唐霜的博客】 this is why this is【原创内容,转载请注明出处】转载请注明出处:www.tangshuang.net not point to instan【未经授权禁止转载】转载请注明出处:www.tangshuang.netce of this component【本文首发于唐霜的博客】原创内容,盗版必究。. Let’s look i【转载请注明来源】【版权所有,侵权必究】nto this code:
【本文受版权保护】【作者:唐霜】<a href="" onclick="alert(this.href)">click</a>
You know what this p【原创内容,转载请注明出处】【原创不易,请尊重版权】oint to here, so whe原创内容,盗版必究。【原创内容,转载请注明出处】n you use a componen【作者:唐霜】转载请注明出处:www.tangshuang.nett method as a event 【访问 www.tangshuang.net 获取更多精彩内容】【版权所有,侵权必究】callback function, t【原创不易,请尊重版权】本文作者:唐霜,转载请注明出处。his in the function 著作权归作者所有,禁止商业用途转载。【未经授权禁止转载】does not referer to 著作权归作者所有,禁止商业用途转载。著作权归作者所有,禁止商业用途转载。the instance of comp转载请注明出处:www.tangshuang.net【本文受版权保护】onent. So another wa【转载请注明来源】著作权归作者所有,禁止商业用途转载。y to solve this prob未经授权,禁止复制转载。【访问 www.tangshuang.net 获取更多精彩内容】lem is to bind this 未经授权,禁止复制转载。转载请注明出处:www.tangshuang.netwhen you use the met原创内容,盗版必究。【未经授权禁止转载】hod, like:
原创内容,盗版必究。【作者:唐霜】export default class MyComponent extends Component {
constructor() {
// do not use bind sentence
}
render() {
return <a onClick={this.say.bind(this)}>click</a>
}
}
Now you can use this原创内容,盗版必究。【作者:唐霜】 in say as want you 【版权所有,侵权必究】【作者:唐霜】want.
【版权所有】唐霜 www.tangshu【转载请注明来源】【本文首发于唐霜的博客】ang.net【原创内容,转载请注明出处】
