Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js & node env checker #94

Open
xgqfrms opened this issue Nov 15, 2019 · 0 comments
Open

js & node env checker #94

xgqfrms opened this issue Nov 15, 2019 · 0 comments

Comments

@xgqfrms
Copy link
Owner

xgqfrms commented Nov 15, 2019

js env check

js & node env checker

"use strict";

/**
 * 
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2019-11-14
 * 
 * @description 写个方法判断当前脚本运行在浏览器还是node环境中 js
 * @augments 
 * @example 
 * @link https://github.com/haizlin/fe-interview/issues/1514#issuecomment-553188594
 * 
 */

let log = console.log;

log(`js env`, typeof window === 'undefined' ? 'Node' : 'Browser');


log(`Node global`, global);
log(`Browser window`, window);
// ReferenceError: window is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant