Home › Forums › Back End › php download multiple files problem. › Reply To: php download multiple files problem.
Since I’m new I’ve never seen javascript written that way yet.
Are you asking about this part?
(function(){
/* stuff . . . */
})();
That’s an anonymous (unnamed) function expression (meaning it executes right away, without needing to be called).
Writing JS this way is called the “module” pattern. It allows me to write my code without worrying about naming conflicts from other scripts, and without causing any problems for other scripts that might run later. Likewise, it allows me to control how my script interacts with the rest of the browser environment (though I have no need to do that in this example).
Functions in JS are closures, which literally means that the function “closes” around everything inside it, creating a private and stateful place for its code to execute. It’s like a house that you can reach out of when needed, but no one else can reach in. You can read more here if you’re interested, but for now, all that’s really important is that it “happens.”