Quotes help make search much faster. Example: "Practice Makes Perfect"

Wednesday, December 5, 2012

Codecademy: Codeyear Sweet Inheritance


//sample solution


// we set up a base class
function Candy() {
    this.sweet = true;
}

// create a "Chocolate" class with a "type" argument
function Chocolate(type) {
this.type = type;
}

// say that Chocolate inherits from Candy
Chocolate.prototype = new Candy();

// create a "choc" object using the Chocolate constructor
// that has a "type" of "milk"
var choc = new Chocolate("milk");

// print the sweet and type properties of choc
console.log(choc.sweet);
console.log(choc.type);

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts