Hi.
It’s to preserve the contents of the list set at the top of the script, in case it’s needed again somewhere else in the script.
The list passed to the handler is the actual one set at the top of the script. Although the extensionList variables inside and outside the handler are different variables with the same name, the list they contain is initially the same one. copy extensionList to extensionList makes a copy of the list and resets the local extensionList variable to the copy, so that any changes made during the repeat which follows happen in the copy and not in the original.
It may be a bit confusing that I’ve used the same variable label throughout. But it’s nothing to do with the variables, it’s to do with the list itself. A copy would still have to be made (if you wanted to preserve the original) even if the variables all had different labels. It’s something of which you have to be aware when passing lists to handlers or assigning them to other variables.
set extensionList to {"pdf", "zip", "dmg", "jpg"}
set sourceFolder to (path to downloads folder)
set myFileList to its listFilesWithGivenExtensions(sourceFolder, extensionList)
on listFilesWithGivenExtensions(theSourceFolder, theExtensionList)
-- Blah blah blah
copy theExtensionList to extensionListCopy -- Make a copy of the list.
repeat with thisExtension in extensionListCopy
-- Possibly modify the copy.
end repeat
-- etc.
end listFilesWithGivenExtensions