4

我正在使用自私的 javascript 库来使 javascript 中的继承更容易。例如我有两个对象

var Foo = Base.extend({
      initialize: function(){
        this.some_param = 1;
      }
    }),
    Bar = Base.extend({
      initialize: function(){
        this.another_param = 2;
      }
    });

如何从 Bar 初始化程序调用 Foo 初始化程序?

4

1 回答 1

2
var Foo = Base.extend({
      initialize: function(){
        this.some_param = 1;
      }
    }),
    Bar = Base.extend({
      initialize: function(){
        Foo.initialize.call(this); // <------- here
        this.another_param = 2;
      }
    });
于 2013-11-13T03:41:38.493 回答