I'm new to prototypal inheritance so I'm trying to understand the 'right' way. I thought I could do this:
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
var tbase = {};
tbase.Tdata = function Tdata() {};
tbase.Tdata.prototype.say = function (data) {
console.log(data);
};
var tData = new tbase.Tdata();
tbase.BicData = Object.create(tData);
tbase.BicData.prototype.say = function (data) {
console.log("overridden: " + data)
};
tbase.BicData.prototype.shout = function (data, temp) {
console.log("SHOUT: " + data + ", " + temp)
};
var test = new tbase.BicData();
tData.say("test1");
test.say("test2");
test.shout("test3", "hope");
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
var tbase = {};
tbase.Tdata = function Tdata() {};
tbase.Tdata.prototype.say = function (data) {
console.log(data);
};
var tData = new tbase.Tdata();
tbase.BicData = Object.create(tData);
tbase.BicData.prototype.say = function (data) {
console.log("overridden: " + data)
};
tbase.BicData.prototype.shout = function (data, temp) {
console.log("SHOUT: " + data + ", " + temp)
};
var test = new tbase.BicData();
tData.say("test1");
test.say("test2");
test.shout("test3", "hope");
But instead I get "tbase.BicData.prototype is undefined"
In Java speak, what I want is to have Tdata as a boilerplate 'interface', BicData to be an implementation of that that, and then to instantiate objects from it.
Where am I going wrong?