我的问题是我需要处理矩形的多个事件。听起来很简单,例如这行得通
node.click(function(e){
click(); // this is function defined in same scope, it works ok
});
node.mouseout(function(e){
mouseout();
});
但是,我想自动化这个,所以它应该是这样的:
var events = new Array("click", "mouseout");
for(var i in events){
node[events[i]](function(e){
events[i](); /*THIS is problem, no matter if it is click or mouseout
this always fires function with same name as last item
in events array (in this case mouseout)
*/
}
}
你知道为什么我应该如何解决它吗?