1、 文件位置

lodash\dist\lodash.js

2、

;(function() {
}.call(this))   

这个函数的call方法的含义:谁调用它,this就指向当前的环境
 

call()方法在使用一个指定的this值和若干个指定的参数值的前提下调用某个函数或方法。

 fun.call( thisArg[, arg1[, arg2[, ...]]])

thisArg在函数运行时指定的this值。指定的this值并不一定是该函数执行时真正的this值,如果这个函数处于非严格模式下,则指定为ull何undefined的this值会自动指向全局函数(浏览器中就是window对象)。同时值为原始值(数字、字符串、布尔值)的this会指向该原始值的自动包装对象。

3、

line:400

  /* 
   * Detect free variable `global` from Node.js.
   * 从nodejs中发现自由变量global,就使用nodejs的global 
   */
  
  var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;

  /* 
   * Detect free variable `self`. 
   * 发现自由变量self,代表当前作用域
   */
   
  var freeSelf = typeof self == 'object' && self && self.Object === Object && self;

  /** Used as a reference to the global object. */
  var root = freeGlobal || freeSelf || Function('return this')();
  关于Function('return this')();的用法

4、 lodash和“_”如何被划等号

 
 line:1405
 
 function runInContext(context) {}
 
 line:16705
 
   // Export lodash.

    var _ = runInContext();
    
    // Some AMD build optimizers, like r.js, check for condition patterns like:
      if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
    // Expose Lodash on the global object to prevent errors when Lodash is
    // loaded by a script tag in the presence of an AMD loader.
    // See http://requirejs.org/docs/errors.html#mismatch for more details.
    // Use `_.noConflict` to remove Lodash from the global object.
    root._ = _;

    // Define as an anonymous module so, through path mapping, it can be
    // referenced as the "underscore" module.
    define(function() {
      return _;
    });

 }
  // Check for `exports` after `define` in case a build optimizer adds it.
  else if (freeModule) {
// Export for Node.js.
(freeModule.exports = _)._ = _;
// Export for CommonJS support.
freeExports._ = _;
 }
  else {
// 赋值给全局对象。
root._ = _;
root.lodash = _;}

5、这里如何将lodash imports _ 有何含义?


 
    lodash.templateSettings=  {
    'escape': reEscape,
    'interpolate': reInterpolate,
    ‘variable’: '',
    'imports':{
        
        '_':lodash
    }
};

可以用如下方法调用interpolate

[options.interpolate=_.templateSettings.interpolate]    

原型继承

    lodash.prototype = baseLodash.prototype;
    lodash.prototype.constructor = lodash;

aprildove
233 声望15 粉丝

一个前端