skip to main |
skip to sidebar
RSS Feeds
ASP.NET, JavaScript, Oracle and SQL articles and code.
ASP.NET, JavaScript, Oracle and SQL articles and code.
9:38 AM
Posted by Michael Heliso
Here are two different approaches in using the previous motioned inheritance technique.
1. Standard way where all members are public:
var Human = MG.Class.Create({
Gender: null,
constructor: function(gender) {
this.Gender = gender;
},
IsMale: function() {
return this.Gender == 'F' ? false : true;
},
GenderString: function() {
return this.Gender == 'F' ? "female" : "male";
},
ToOverride: function() { return "Called from Human"; }
}, null, null);
var Individual = MG.Class.Create({
Unique: null,
constructor: function(unique) {
this.Unique = unique;
},
IsUnique: function() {
return this.Unique ? "Yes" : "No";
},
DummyMethod: function() {
return "Individual dummy method.";
},
ToOverride: function() { return "Called from Individual which is " + (this.Unique ? "unique" : "not unique") + " / " + this.base(); }
}, Human, null);
var Person = MG.Class.Create({
constructor: function(firstName, lastName, birthDate) {
this.FirstName = firstName;
this.LastName = lastName;
this.BirthDate = birthDate;
},
GetName: function() {
return this.FirstName + " " + this.LastName;
},
GetDetails: function() {
return this.GetName() + " it's a " + this.GenderString() + " borned on date " + this.BirthDate;
},
ToOverride: function() { return "Called from Person with first name " + this.FirstName + " / " + this.base(); }
}, Individual, null);
var Jhon = MG.Class.Create({
constructor: function(age) {
this.Age = age;
},
GetDetails: function() {
return this.GetName() + " it's a " + this.GenderString() + " borned on date " + this.BirthDate + ".";
},
ToOverride: function() { return "Called from Jhon/ " + this.base(); }
}, Person, null);
var Human = MG.Class.Create({
constructor: function(gender) {
this.Gender = gender;
return { IsMale: function() {
return this.Gender == 'F' ? false : true;
},
GenderString: function() {
return this.Gender == 'F' ? "female" : "male";
},
ToOverride: function() { return "Called from Human"; }
};
}
}, null, null);
var Individual = MG.Class.Create({
constructor: function(unique) {
this.Unique = unique;
var PrivateDummyMethod = function() {
return "Individual dummy method.";
};
return { IsUnique: function() {
return this.Unique ? "Yes" : "No";
},
ToOverride: function() { return "Called from Individual / " + this.base(); }
};
}
}, Human, null);
var Person = MG.Class.Create({
constructor: function(firstName, lastName, birthDate) {
this.FirstName = firstName;
this.LastName = lastName;
this.BirthDate = birthDate;
return { GetName: function() {
return this.FirstName + " " + this.LastName;
},
GetDetails: function() {
return this.GetName() + " it's a " + this.GenderString() + " borned on date " + this.BirthDate;
},
ToOverride: function() { return "Called from Person / " + this.base(); }
};
}
}, Individual, null);
var Kate = MG.Class.Create({
constructor: function(age) {
this.Age = age;
return { GetDetails: function() {
return this.GetName() + " it's a " + this.GenderString() + " borned on date " + this.BirthDate + ".";
},
ToOverride: function() { return "Called from Kate/ " + this.base(); }};
}
}, Person, null);