// CSE 341, Autumn 2010, Marty Stepp // An example that illustrates the need for a wrapping function to get proper // closure around the value of i for each funcs[i] element. var funcs = []; for (var i = 0; i < 5; i++) { funcs[i] = (function(w) { return function() { return w; }; })(i); } /* The following version does not work: var funcs = []; for (var i = 0; i < 5; i++) { funcs[i] = function() { return i; }; } */ /* regular expression to search and replace "last, first" names with "first last": line = line.replace(/([a-zA-Z]+), ([a-zA-Z]+)/, "$2 $1"); */