Global Libraries
Global library code is usually extremely simple.
A global “Hello, world” library might look like
this:
function createGreeting(s) {
return "Hello, " + s;
}
// Web
window.createGreeting = function (s) {
return "Hello, " + s;
};
// Node
global.createGreeting = function (s) {
return "Hello, " + s;
};
// Potentially any runtime
globalThis.createGreeting = function (s) {
return "Hello, " + s;
};
When looking at the code of a global library,
you’ll usually see:
- Top-level var statements or function declarations
- One or more assignments to window.someName
- Assumptions that DOM primitives like document or window exist