4 ms·
You can serve JS code that is wrapped in an anonimous function itself.
by v413 13y ago
You can serve JS code that is wrapped in an anonimous function itself.
- philipwalton 13y agoYes, but that doesn't actually solve the problem. How is that code going to interact with your existing objects unless those objects are in the global scope? If both the requester of the AJAX call and the receiver are in the same closure, there's no need for those objects to be globally accessible.
- homakov 13y agoyes this is another good reason to avoid it
- v413 13y agoIt is possible , e.g. if your javascript on the page is already using a common js module system, you can simply "require" the necessary modules. In addition, you can have a global pub/sub system in place (that you can "require" from you inlined script) and fire events. This will really help for decoupling. Usually you need inlined js along with the served html so that you attach behavior from within that inlined script. This is again easy to do from a "closured" piece of code.