0

Inheritance

Hello,

I want to use the Extends functionality from the framework so that my classes could inherit from each other.
Basically I have this class:

CODEBOX
var FreeAreaView = new KONtx.Class({
ClassName: 'FreeAreaView',

Extends: MyCustomClass,

initView: function() {

},

createView: function() {

},

updateView: function() {

}
});


I don't want to overwrite the initView definition from the base class, I just want to call the one from MyCustomClass with different parameters.
I know this is a noobish question, but I've searched the forum and haven't found anything.

Thank you for your time,
Florin

by
10 Replies
  • Change "Extends: MyCustomClass," to the class you want to extend. It will not write over the class within the platform.
    0
  • Sorry I wasn't clear before. What I want is this: in the initView() function of my FreeAreaView class, to call the initView() function of MyCustomClass with some parameters.
    The ideea is that I have several classes which extend MyCustomClass, and they are basically the same, only minor differences.
    Thanks for the quick response!
    0
  • Just don't define the function and it will be called.

    leave out the initView() or any other functions you don't want to overwrite. They extension will inherit all the previous classes functions/behaviors.
    0
  • Yes, but can I call the initView from the parent with some sort of parameters? Something like: parent.initView(some_data)
    0
  • Sure. I would try this approach.

    CODE
    var MyCustomClass = new KONtx.Class({
    ClassName: 'MyCustomClass',

    otherinitView: function(vals) {

    },

    createView: function() {

    },

    updateView: function() {

    }
    });


    CODE
    var FreeAreaView = new KONtx.Class({
    ClassName: 'FreeAreaView',

    Extends: MyCustomClass,

    initView: function() {
    this.otherinitView({myvals});
    },

    createView: function() {

    },

    updateView: function() {

    }
    });
    0
  • QUOTE (WidgetRealm @ Feb 4 2011, 09:30 AM) <{POST_SNAPBACK}>
    Sure. I would try this approach.

    CODE
    var MyCustomClass = new KONtx.Class({
    ClassName: 'MyCustomClass',

    otherinitView: function(vals) {}
    });


    CODE
    var FreeAreaView = new KONtx.Class({
    ClassName: 'FreeAreaView',
    Extends: MyCustomClass,

    initView: function() {
    this.otherinitView({myvals});
    }
    });



    I would use this approach instead, as this is used throughout the YDK, and is more Mootools like:

    CODE
    var MyCustomClass = new KONtx.Class({
    ClassName: 'MyCustomClass',

    initView: function(vals) {},
    });


    CODE
    var FreeAreaView = new KONtx.Class({
    ClassName: 'FreeAreaView',
    Extends: MyCustomClass,

    initView: function() {
    this.parent({myvals});
    }
    });
    0
  • You will need to do a check for the "vals" in the initial initView(). If you every use the Class without extending it will be called with no values initially.
    0
  • QUOTE (WidgetRealm @ Feb 5 2011, 09:45 AM) <{POST_SNAPBACK}>
    You will need to do a check for the "vals" in the initial initView(). If you every use the Class without extending it will be called with no values initially.

    Why would it be any different if he called the class directly or not?

    He can just as easily instantiate the base class with an initial configuration object.
    0
  • The thought was that he should not assume the "vals" are always available going into the view if the data is based off information coming from an external source. Not really clear in the explanation now that I reread it... :)
    0
  • QUOTE (WidgetRealm @ Feb 7 2011, 12:22 PM) <{POST_SNAPBACK}>
    The thought was that he should not assume the "vals" are always available going into the view if the data is based off information coming from an external source. Not really clear in the explanation now that I reread it... :)
    0

Recent Posts

in Getting Started / Beginners - Yahoo! TV Widgets