Dojo无参数构造函数使用参数调用基础构造函数

时间:2011-07-19 18:58:00

标签: javascript oop inheritance constructor dojo

是否可以在javascript / dojo工具箱中使用explicitely调用基础构造函数 设置构造函数参数(在继承类的构造函数之外)

dojo.provide("ClassA");
dojo.declare("ClassA", null,
{
  constructor: function(text)
  {
    console.log(text);
  }
});

dojo.provide("ClassB");
dojo.declare("ClassB", ClassA,
{
   constructor: function()
   {
      // want to call the base constructor of Class A with "Hello "
      console.log("world!");
   }
});

我可以使用this.inherited(arguments,[“Hello”])但这将产生两个基本构造函数的调用(一个没有,一个带给定的参数)。 (将产生以下输出:undefined \ n“Hello”\ n“world!”)。

我已经尝试过使用以下方法:

dojo.mixin(this, "Hello");
dojo.safeMixin(this, "Hello");
dojo.mixin(ClassA, "Hello");
...

但我做的所有事情似乎都是两次调用基础构造函数。有什么建议吗?

1 个答案:

答案 0 :(得分:4)

您需要关闭自动构造函数chaing。请查看here以获取有关如何手动覆盖自动行为的示例。

相关问题