Skip to content

Instantly share code, notes, and snippets.

@jgable
Created April 18, 2012 23:21
minimum JS - Classes 2
// 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