39页,给出了一个讲解闭包的代码:
var add_the_handlers=function(nodes){
var i;
for(i=0;i
return function(e){
alert(e);
};
}(i);
}
}
这个函数的目的是: Make a function that assigns event handler functions to an array of nodes the right way. When you click on a node, an alert box will display the ordinal of the node.
但是代码中alert的却是'e',这个是event,如果是这样的话,点击每个节点,都是alert的 '[object MouseEvent]'
我们只要把alert(e)改为alert(i)就正确了,就可以alert出这个节点在所有选中的节点中的序数了。
