Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Extending/Inheriting using puremvc.define  (Read 7863 times)
saad
Sr. Member
****
Posts: 65


View Profile Email
« 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?
« Last Edit: April 07, 2012, 08:58:51 by saad » Logged
saad
Sr. Member
****
Posts: 65


View Profile Email
« Reply #1 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.

Logged
saad
Sr. Member
****
Posts: 65


View Profile Email
« Reply #2 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.
« Last Edit: April 09, 2012, 10:51:25 by saad » Logged
Pages: [1]
Print