Skip to content

如何判断当前脚本运行在浏览器还是 node 环境中?

参考答案:

js
this === window ? 'browser' : 'node';

通过判断 Global 对象是否为 window,如果不为 window,当前脚本没有运行在浏览器中。