Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 这是什么意思?这个[';find';](函数(模型){…})_Javascript_Backbone.js - Fatal编程技术网

Javascript 这是什么意思?这个[';find';](函数(模型){…})

Javascript 这是什么意思?这个[';find';](函数(模型){…}),javascript,backbone.js,Javascript,Backbone.js,我试图理解主干集合findWhere()函数是如何工作的,我在代码中看到了这一点: // Return models with matching attributes. Useful for simple cases of // `filter`. where: function(attrs, first) { var matches = _.matches(attrs); return this[first ? 'find' : 'filter'

我试图理解主干集合
findWhere()
函数是如何工作的,我在代码中看到了这一点:

    // Return models with matching attributes. Useful for simple cases of
    // `filter`.
    where: function(attrs, first) {
      var matches = _.matches(attrs);
      return this[first ? 'find' : 'filter'](function(model) {
        return matches(model.attributes);
      });
    },

    // Return the first model with matching attributes. Useful for simple cases
    // of `find`.
    findWhere: function(attrs) {
      return this.where(attrs, true);
    },
我试图理解这部分的作用:

  return this[first ? 'find' : 'filter'](function(model) {
    return matches(model.attributes);
  });
这部分
这个['find'](函数(模型){…})
实际上是做什么的?

它是这样的

  • 是一个
    对象

  • [first'find':'filter']
    检查bool
    first
    是否为正数,然后返回
    'find'
    否则
    'filter'
    这是通过括号符号访问的函数引用
    []
    。简而言之,使用三元运算符通过bracker表示法访问函数引用

  • (…){}
    是对该函数的调用
      事情是这样的

      • 是一个
        对象

      • [first'find':'filter']
        检查bool
        first
        是否为正数,然后返回
        'find'
        否则
        'filter'
        这是通过括号符号访问的函数引用
        []
        。简而言之,使用三元运算符通过bracker表示法访问函数引用

      • (…){}
        是对该函数的调用
      这部分等于:

      this.find(function(model){ ... })
      
      所以答案是:它是对象的方法
      find
      ,这个是用参数调用的(我假设它是回调:)
      函数(模型){…}

      这部分等于:

      this.find(function(model){ ... })
      

      所以答案是:这是对象的方法
      find
      ,这个是用参数调用的(我假设它是回调:)
      函数(模型){…}
      ,在javascript中,你可以用括号符号代替点符号,括号符号在你正在使用的这种情况下非常方便。因此,以下内容是相同的:

      foo.['bar']
      foo.bar()
      

      在这方面:

      return this[first ? 'find' : 'filter'](function(model) {
      

      如果第一个值返回true,则将使用
      this.find()
      ,否则将使用
      this.filter()

      您可以在javascript中使用括号表示法而不是点表示法,括号表示法在这样的情况下非常方便。因此,以下内容是相同的:

      foo.['bar']
      foo.bar()
      

      在这方面:

      return this[first ? 'find' : 'filter'](function(model) {
      
      如果第一个值返回true,则将使用this.find(),否则将使用this.filter()。

      return this[first ? 'find' : 'filter'](function(model) {
          return matches(model.attributes);
      });
      

      var functionName = (first ? 'find' : 'filter');
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      var functionName;
      if(first){
          functionName = 'find';
      } else {
          functionName = 'filter';
      }
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      if(first){
          return this['find'](function(model) {
              return matches(model.attributes);
          });
      } else {
          return this['filter'](function(model) {
              return matches(model.attributes);
          });
      }
      
      if(first){
          return this.find(function(model) {
              return matches(model.attributes);
          });
      } else {
          return this.filter(function(model) {
              return matches(model.attributes);
          });
      }
      
      这和

      var functionName = (first ? 'find' : 'filter');
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      var functionName;
      if(first){
          functionName = 'find';
      } else {
          functionName = 'filter';
      }
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      if(first){
          return this['find'](function(model) {
              return matches(model.attributes);
          });
      } else {
          return this['filter'](function(model) {
              return matches(model.attributes);
          });
      }
      
      if(first){
          return this.find(function(model) {
              return matches(model.attributes);
          });
      } else {
          return this.filter(function(model) {
              return matches(model.attributes);
          });
      }
      
      这和

      var functionName = (first ? 'find' : 'filter');
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      var functionName;
      if(first){
          functionName = 'find';
      } else {
          functionName = 'filter';
      }
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      if(first){
          return this['find'](function(model) {
              return matches(model.attributes);
          });
      } else {
          return this['filter'](function(model) {
              return matches(model.attributes);
          });
      }
      
      if(first){
          return this.find(function(model) {
              return matches(model.attributes);
          });
      } else {
          return this.filter(function(model) {
              return matches(model.attributes);
          });
      }
      
      这和

      var functionName = (first ? 'find' : 'filter');
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      var functionName;
      if(first){
          functionName = 'find';
      } else {
          functionName = 'filter';
      }
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      if(first){
          return this['find'](function(model) {
              return matches(model.attributes);
          });
      } else {
          return this['filter'](function(model) {
              return matches(model.attributes);
          });
      }
      
      if(first){
          return this.find(function(model) {
              return matches(model.attributes);
          });
      } else {
          return this.filter(function(model) {
              return matches(model.attributes);
          });
      }
      
      我希望这能把事情弄清楚。

      return this[first ? 'find' : 'filter'](function(model) {
          return matches(model.attributes);
      });
      

      var functionName = (first ? 'find' : 'filter');
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      var functionName;
      if(first){
          functionName = 'find';
      } else {
          functionName = 'filter';
      }
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      if(first){
          return this['find'](function(model) {
              return matches(model.attributes);
          });
      } else {
          return this['filter'](function(model) {
              return matches(model.attributes);
          });
      }
      
      if(first){
          return this.find(function(model) {
              return matches(model.attributes);
          });
      } else {
          return this.filter(function(model) {
              return matches(model.attributes);
          });
      }
      
      这和

      var functionName = (first ? 'find' : 'filter');
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      var functionName;
      if(first){
          functionName = 'find';
      } else {
          functionName = 'filter';
      }
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      if(first){
          return this['find'](function(model) {
              return matches(model.attributes);
          });
      } else {
          return this['filter'](function(model) {
              return matches(model.attributes);
          });
      }
      
      if(first){
          return this.find(function(model) {
              return matches(model.attributes);
          });
      } else {
          return this.filter(function(model) {
              return matches(model.attributes);
          });
      }
      
      这和

      var functionName = (first ? 'find' : 'filter');
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      var functionName;
      if(first){
          functionName = 'find';
      } else {
          functionName = 'filter';
      }
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      if(first){
          return this['find'](function(model) {
              return matches(model.attributes);
          });
      } else {
          return this['filter'](function(model) {
              return matches(model.attributes);
          });
      }
      
      if(first){
          return this.find(function(model) {
              return matches(model.attributes);
          });
      } else {
          return this.filter(function(model) {
              return matches(model.attributes);
          });
      }
      
      这和

      var functionName = (first ? 'find' : 'filter');
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      var functionName;
      if(first){
          functionName = 'find';
      } else {
          functionName = 'filter';
      }
      return this[functionName](function(model) {
          return matches(model.attributes);
      });
      
      if(first){
          return this['find'](function(model) {
              return matches(model.attributes);
          });
      } else {
          return this['filter'](function(model) {
              return matches(model.attributes);
          });
      }
      
      if(first){
          return this.find(function(model) {
              return matches(model.attributes);
          });
      } else {
          return this.filter(function(model) {
              return matches(model.attributes);
          });
      }
      
      我希望这能把事情弄清楚