1.事件绑定到this
export default function bindHandlers(obj) {
Object.getOwnPropertyNames(Object.getPrototypeOf(obj)).forEach((property) => {
if (typeof(obj[property]) === 'function' && property.indexOf('handle') === 0) {
obj[property] = obj[property].bind(obj);
}
});
}
使用方法:直接在组件的构造器里面加上 bindHandlers(this);即可。但要绑定的方法必须是以handle
博客介绍了将事件绑定到this的使用方法,即在组件的构造器里添加bindHandlers(this),且要绑定的方法需以handle开头。
573

被折叠的 条评论
为什么被折叠?



