Beachwalker
Beachwalker

Reputation: 7915

Dojo parameterless constructor calls base constructor with parameters

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?

Upvotes: 3

Views: 2466

Answers (1)

emboss
emboss

Reputation: 39650

You need to turn off automatic constructor chaing. Take a look here for an example of how to manually override automatic behaviour.

Upvotes: 4

Related Questions