定义函数foo使得init对应的函数调用执行的时候,将其对应的事件(click),传递给dosomething方法并且执行
dosomething。
Var handler={
id:'123456'
init:function(){
document.addEventListener('click'foo);},
doSomething:function(type){
console.log('Handling'+type+'for'+
this.id);
};
```javascript
var handler = {
id: '123456',
init: function() {
document.addEventListener('click', foo);
},
doSomething: function(type) {
console.log('Handling' + type + 'for' + this.id);
}
}
function foo(e) {
handler.doSomething(e.type)
}
handler.init()
```