{"_id":"global-object","_rev":"31798","name":"global-object","description":"just the global object","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"webreflection","email":"andrea.giammarchi@gmail.com"}],"time":{"modified":"2021-06-03T10:05:27.000Z","created":"2015-04-17T17:12:06.817Z","1.0.0":"2015-04-17T17:12:06.817Z"},"users":{},"author":{"name":"Andrea Giammarchi"},"repository":{"type":"git","url":"https://github.com/WebReflection/global-object.git"},"versions":{"1.0.0":{"name":"global-object","version":"1.0.0","description":"just the global object","main":"global-object.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"https://github.com/WebReflection/global-object.git"},"keywords":["global"],"author":{"name":"Andrea Giammarchi"},"license":"WTFPL","bugs":{"url":"https://github.com/WebReflection/global-object/issues"},"homepage":"https://github.com/WebReflection/global-object","gitHead":"7590925460677e5fcf05de3092e34732c0523848","_id":"global-object@1.0.0","_shasum":"2a1b45e901d55e4773154f12f0cec1ef9aba5f9f","_from":".","_npmVersion":"2.6.0","_nodeVersion":"1.4.1","_npmUser":{"name":"webreflection","email":"andrea.giammarchi@gmail.com"},"maintainers":[{"name":"webreflection","email":"andrea.giammarchi@gmail.com"}],"dist":{"shasum":"2a1b45e901d55e4773154f12f0cec1ef9aba5f9f","size":1596,"noattachment":false,"key":"/global-object/-/global-object-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/global-object/download/global-object-1.0.0.tgz"},"directories":{},"publish_time":1429290726817,"_cnpm_publish_time":1429290726817,"_hasShrinkwrap":false}},"readme":"# global-object\n\nThere are at least 3 different ways to reference the global object mentioned in ES6/2015\n\n  * `window` historically on HTML pages\n  * `self` in Workers, and historically on HTML pages too\n  * `global` in basically all server side implementation of JavaScript\n\nIf we search in Github, the summed amount of `typeof window` or `typeof global` checks,\nmostly to understand which one is available, is about 23 millions of times.\n\nThis is madness, and since there's no reason at all to prefer anything different from `global`\nfor an object defined indeed as the global object in the global scope, I've decided to create\nthis page in order to put an end to all this.\n\n- - - -\n\nForget about `window` and `self` in Workers, normalize your work-flow once for all\nand with or without browserify in place!\n\n\n### As first script in your page\nThis is the most straight forward way to have it defined everywhere as such\n```html\n<script>var global=global||this;</script>\n```\nNo need to disturb the network, no need to ever update the script even if a browser\nwill eventually expose `global` reference. It goes there to stay.\n\n\n### As first script in your Worker\nSame goes with Web Workers and others, the code is exactly the same, without the node:\n```html\nvar global=global||this;\n```\nForget about `self` or `typeof window` checks, we've got `global`!\n\n\n### As anything else\nES6, node itself, whatever ... \n```js\n// ES6\nimport global from 'global-object';\n\n// npm require\nvar global = require('global-object');\n\n// browser\nscript.src = 'global-object.js';\n```\nJust use [global-object](global-object.js)\n\n\n### Strict compatible!\nYes, the `this` reference in the global scope is always the global object.\nIn HTML pages like in workers, it will work everywhere even after `\"use strict\"` directive!\n\n\n### Content Security Policy Compatible\nUsing this meta will solve all problems:\n```html\n<meta http-equiv=\"Content-Security-Policy\" content=\"script-src 'unsafe-inline' 'self' 'sha1-WWQNP0ydesPxK1yAm94nH5bQoIo=' 'sha256-5rMu52Es8MMWNrCqRkunbIAeVDz8iJ63wD0rPm57xi4='\">\n```\nGreat, no network request required, and `global` available under CSP too!\n\n\n### License\nNope, nothing ... do what you want, literally!","_attachments":{},"homepage":"https://github.com/WebReflection/global-object","bugs":{"url":"https://github.com/WebReflection/global-object/issues"},"license":"WTFPL"}