Hi everyone
I am currently reading a book, and I don't seem to under the author,
(Crockfold) when he says this:
//Bad examples
var add_the_handlers = function(nodes){
var i;
for (i = 0; i < nodes.length; i += 1) {
nodes[i].onclick = function(e){
alert(i);
}
}
};
//Better example
var add_the_handlers = function(nodes){
var i;
for (i = 0; i < nodes.length; i++) {
nodes[i].onclick = function(i){
return function(e){
alert(i);
};
}(i);
}
};
Both of these functions are suppose to assign event handler functions
to an array of nodes.
How do I test both of these?