This is a migrated thread and some comments may be shown as answers.

Inheritance With Kendo UI - Calling base class constructor

1 Answer 91 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sakthivel
Top achievements
Rank 1
Sakthivel asked on 01 Aug 2012, 01:44 PM
I am experimenting with "kendo.Class.extend()".

When I inherit a new class from a base class, how can i call the base class constructor from within the derived class constructor?

The below didn't work for me.

var ClsPerson = kendo.Class.extend(
                {
                    FirstName:"<none>", LastName: "<none>", Married: false, 
                    Display: function() { alert("I am " + this.FirstName + " " + this.LastName); },
                    init: function(FirstName, LastName)
                    {
                        if (FirstName) this.FirstName = FirstName;
                        if (LastName) this.LastName = LastName;
                    }
                });
var ClsParent = ClsPerson.extend(
                {
                    SpouseName: "<none>",
                    init: function(FirstName, LastName, SpouseName)
                    {
                        //if (FirstName) this.FirstName = FirstName;
                        //if (LastName) this.LastName = LastName;
                        ClsPerson(FirstName, LastName);
                        if (SpouseName) this.SpouseName = SpouseName;
                    }
                });

var Parent1 = new ClsParent("Sakthivel", "S", "Sangitha S");
Parent1.Display();
alert(Parent1.SpouseName);

I tried calling the base class constructor like "ClsPerson(FirstName, LastName); ", but didn't get the desired results.

1 Answer, 1 is accepted

Sort by
0
Maxim
Top achievements
Rank 1
answered on 10 Aug 2012, 07:31 PM
ClsPerson.call(this, ...);
Tags
General Discussions
Asked by
Sakthivel
Top achievements
Rank 1
Answers by
Maxim
Top achievements
Rank 1
Share this question
or