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