Last active
October 16, 2016 02:14
-
-
Save cazala/44fab99936251cdf7a582163915a5fe7 to your computer and use it in GitHub Desktop.
How to tell if inside a Browser, WebWorker or NodeJS from Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (typeof window === 'object') { | |
| // Browser | |
| } else if (typeof importScripts === 'function') { | |
| // WebWorker | |
| } else if (typeof process === 'object' && typeof require === 'function') { | |
| // NodeJS | |
| } else { | |
| // shell | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment