Created
April 18, 2012 23:21
minimum JS - Classes 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The classical prototype way | |
/* Define a constructor */ | |
function Baby(name, sex, says) { | |
// Set some variables on the object | |
this.name = name; | |
this.sex = sex; | |
this.says = says; | |
} | |
/* Define the baby.speak() method */ | |
Baby.prototype.speak = function() { | |
return this.says; | |
}; | |
/* This is how we instantiate our Baby class */ | |
var baby2 = new Baby("wootsy", "M", "googoo"); // As in Dolls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment