I have a confusion with Crockford recommended inheritance, what is the major difference between the Crockford method and the generic (default) way.
//Crockford method
function object(o) {
function F() {}
F.prototype = o;
return new F();
}
The below is more generic way
function Base(name) {
this.name = name;
}
Base.prototype.getName = function () {
return 'Base :' + this.name;
}
function Child(name) {
this.name = name;
}
Child.prototype.getName = function () {
return 'Child :' + this.name;
}
function Kid(name) {
this.name = name;
}
Kid.prototype.getName = function () {
return 'Kid :' + this.name;
}
Child.prototype = new Base ("childBase");
Kid.prototype = new Child ("kidChild");
var base = new Base ("myBase");
var child = new Child("myChild");
var kid = new Kid("myKid");
console.log(base.getName());
console.log(child.getName());
console.log(kid.getName());
What is difference between the above two ?
Actually I am not able to completely understand Crockford method. Could any one help me to figure out the drawbacks in the generic way and advantages in Crockford method.