In the C programming language, there's an include guard which prevents the same header file being included twice:
#ifndef GRANDPARENT_H
#define GRANDPARENT_H
struct foo {
int member;
};
#endif /* GRANDPARENT_H */
In web pages, JavaScript is often used as a header file, too. Sometimes a developer can mistakenly include the same file twice, causing bugs that are hard to debug (examples here).
The proper way to prevent multiple includes of the same file should be an include guard. But what is the proper way to add such a guard to a JavaScript file so that it works without polluting namespace, breaking other script and other unwanted behavior?
This question is not a duplicate of that question, which doesn't talk about the potential problems of using such a guard. Furthermore, it points to another library, while a lightweight, inline solution would be much more welcome.