Dojo 无参数构造函数调用带参数的基本构造函数
是否可以在 javascript / dojo 工具包中显式调用基本构造函数 设置构造函数参数(在继承类的构造函数之外)
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");
...
但我所做的所有事情似乎都调用了基本构造函数两次。有什么建议吗?
Is it possible in javascript / dojo toolkit to call the base constructor with explicitely
set constructor arguments (out of the constructor of the inherited class)
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!");
}
});
I could use this.inherited(arguments, ["Hello "]) but this will produce two calls of the base constructor (one without and one with the given argument).
(will produce output of: undefined\n"Hello "\n"world!").
I already tried using the following ways:
dojo.mixin(this, "Hello");
dojo.safeMixin(this, "Hello");
dojo.mixin(ClassA, "Hello");
...
but all things I did seems to call the base constructor twice. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要关闭自动构造函数链接。请查看此处,了解如何手动覆盖自动行为。
You need to turn off automatic constructor chaing. Take a look here for an example of how to manually override automatic behaviour.