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