如何检查脚本是否在Node.js下运行?

如何检查脚本是否在Node.js下运行?,第1张

如何检查脚本是否在Node.js下运行?

通过寻求CommonJS支持 ,这是Underscore.js库的实现方式:

编辑:对您的更新问题:

(function () {    // Establish the root object, `window` in the browser, or `global` on the server.    var root = this;    // Create a reference to this    var _ = new Object();    var isNode = false;    // Export the Underscore object for **CommonJS**, with backwards-compatibility    // for the old `require()` API. If we're not in CommonJS, add `_` to the    // global object.    if (typeof module !== 'undefined' && module.exports) { module.exports = _; root._ = _; isNode = true;    } else { root._ = _;    }})();

这里的示例保留了Module模式。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5049375.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-15
下一篇2022-11-15

发表评论

登录后才能评论

评论列表(0条)

    保存