账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    关于underscore源码的一点疑问, 涉及node.js模块化
    • 2017-11-10 00:00
    • 11
    39
    0

    以下是源码信息

    
      // Export the Underscore object for **Node.js**, with
      // backwards-compatibility for their old module API. If we're in
      // the browser, add `_` as a global object.
      // (`nodeType` is checked to ensure that `module`
      // and `exports` are not HTML elements.)
      if (typeof exports != 'undefined' && !exports.nodeType) {
        if (typeof module != 'undefined' && !module.nodeType && module.exports) {
          exports = module.exports = _;
        }
        exports._ = _;
      } else {
        root._ = _;
      }

    这段代码应该是针对在nodejs环境中将_的方法挂载到exports._上,但不太懂这段代码具体逻辑:

    1. typeof exports != 'undefined' && !exports.nodeType 为什么不使用严格不等于!==或直接用隐式转换exports && !exports.nodeType;

    2. exports.nodeTypemodule.nodeType 是什么?;

    3. exports = module.exports = _; 这行代码如何理解?。

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部