JS - 通过原型设计填充数组

时间:2015-01-20 23:25:27

标签: javascript

我刚看了下面的JS代码,我有两个问题:

  1. 为什么容器对象不能声明为变量?
  2. 什么是“Array.prototype.push.apply”?
  3. 的Javascript

     Container = function(title, used) {
      this.title = title;
      this.used= !!used;
      this.callbacks = [];
     };
    
    Container.prototype.push = function() {
        Array.prototype.push.apply(this.callbacks);
    };
    

1 个答案:

答案 0 :(得分:0)

Apply在push函数中设置调用对象。但它似乎没有在这里正确使用。有关调用对象,构造函数和原型的更多信息,请参见:https://stackoverflow.com/a/16063711/1641941