object prototyping

by peterbenoit

JavaScript

function Animal(type){
    this.type = type;
    return this;
}

function Dog(name, breed){
    this.name = name;
    this.breed = breed;
    
    Animal.call(this, breed);

    return this;
}
Dog.prototype = new Animal();

function Cat(name, color){
    this.name = name;
    this.color = color;
    
    Animal.apply(this, color);
    return this;
}
Cat.prototype = new Animal();

var Boz = new Dog("Bosley", "Peekapoo");
console.log(Boz);

var Nigel = new Cat("Mr Nigel Murray", ["White","Gray","Dirty"]);
console.log(Nigel);


    
//console.log(Dog("Bosley", "Peekapoo"));  // window
//console.log(Dog.call(this, "Bosley", "Peekapoo"));  // the obj
//console.log(Dog.apply(this, {"Bosley": "Peekapoo"}));  // the obj