在学习ExtJS 4时,我发现在定义一个新类时,可以在initComponent方法中使用this.callParent(arguments)调用父类的构造函数。

我想知道这个arguments变量(我也知道它也可以是argsaarg)在哪里定义,以及它的值分配在哪里。

例如,如果我按以下方式定义我的类(class):

Ext.define('shekhar.MyWindow', {

  extend : 'Ext.Window',
  title : 'This is title',

  initComponent : function() {
    this.items = [
      // whatever controls to be displayed in window
    ];

    // I have not defined argument variable anywhere
    // but still ExtJS will render this window properly without any error
    this.callParent(arguments);
  }

});

有谁知道这个arguments变量的定义位置以及如何为其赋值?

最佳答案

arguments变量是Javascript中的特殊变量,可在任何函数中使用。它不是一个真正的数组,但是包含传递给函数的参数值,可以像数组元素一样对其进行访问(因此,arguments[0]是第一个参数,arguments[1]是第二个参数,依此类推)。

在Mozilla开发人员网络上查看this page,以获取更多信息和示例。

09-10 10:22
查看更多