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