Skip to content

Instantly share code, notes, and snippets.

@zmmbreeze
Created June 20, 2013 08:34
Show Gist options
  • Select an option

  • Save zmmbreeze/5821165 to your computer and use it in GitHub Desktop.

Select an option

Save zmmbreeze/5821165 to your computer and use it in GitHub Desktop.
Detect javascript runtime environment.
function DetectJSEnv() {
if (typeof environment === 'object' && ({}).toString.call(environment) === '[object Environment]') {
// Rhino
// Details on how to detect Rhino: https://github.com/ringo/ringojs/issues/88
return 'rhino';
} else if (typeof(window) === 'undefined') {
// Node.js
return 'node';
} else {
// Browser
return 'browser';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment