15 prototype practice easier way to call meow when there are perhaps several cat objects?


#1

When I completed this task I was left wondering if we could write just one line of code to make all cats meow in the console window instead of having to list each individual object.method( ) ?

// add code here to make the cats meow!
cheshire.meow();
gary.meow();

Cat.prototype.meow( );
prints to console meow once

**Native Browser JavaScript **
Meow!

any ideas? I even gave meow( ); a go but that was a guess I could have left on the shelf hahaha.

// NEW class Cat and its object constructor in literal notation.
function Cat(name, breed) {
    this.name = name;
    this.breed = breed;
}


// we change the 'prototype' for the 'class' 'Cat'. This immediately teaches ALL Cats the new method.
var cheshire = new Cat("Cheshire Cat", "British Shorthair");

var gary = new Cat("Gary", "Domestic Shorthair");

// add a method "meow" to the Cat class that will allow
// all cats to print "Meow!" to the console
// add 'meow' method to Cat object
Cat.prototype.meow = function() {
    //statements;
    console.log("Meow!");
    };

// add code here to make the cats meow!
cheshire.meow();
gary.meow();

#2

You would need a reference to the object that's supposed to meow

Put them all in an array and loop through it