PureMVC Architects Lounge

PureMVC Manifold => Multicore Version => Topic started by: saad on April 07, 2012, 08:47:08



Title: Extending/Inheriting using puremvc.define
Post by: saad on April 07, 2012, 08:47:08
a.js

puremvc.define(
{
    name: 'view.component.a',
   
    constructor: function(){
        alert('inside component a');
    }
}
);

b.js

puremvc.define(
{
    name: 'view.component.b',
    parent: view.component.a,
   
    constructor: function(){
        alert('inside constructor b');
    }
}
);

inside html (as a test)
        <script>
            //var a = new view.component.a();
            var b = new view.component.b();
        </script>

I'm trying to have the super constructor called while instantiating b, please advise. do we access to super something?


Title: Re: Extending/Inheriting using puremvc.define
Post by: saad on April 09, 2012, 04:09:11
after some research in the doc file, I've found the answer, in case I specify my own constructor, I've to call parent constructor manually, but this brings up another problem,

Call super constructor:
view.component.a.call();

The problem is that I've some objects getting instantiated inside "class a", and in my extended "class b", I'm not inheriting them and they're coming off as null.

Please advise.



Title: Re: Extending/Inheriting using puremvc.define
Post by: saad on April 09, 2012, 04:23:01
Solved:

Solution:

1) instead of instantiating objects inside constructor, instantiate objects directly while defining them in the second block {} inside puremvc.define.
2) Call constructor like this -> view.component.a.call(this, 'param1'); and initialize your variables through the constructor.