Skip to content

Instantly share code, notes, and snippets.

@CharlotteGore
Created July 18, 2014 13:16
Show Gist options
  • Save CharlotteGore/a6ee30b00eadd363da56 to your computer and use it in GitHub Desktop.
Save CharlotteGore/a6ee30b00eadd363da56 to your computer and use it in GitHub Desktop.
Very basic Javascript
function Tiger (){
this.name = "";
this.isKing = false;
}
Tiger.prototype = {
getName : function (){
if (this.isKing){
return this.name + ", who is the mother fucking King!";
} else {
return this.name + ", who is a nobody.";
}
},
setName : function (name){
this.name = name;
}
coronate : function (){
this.isKing = true;
}
}
// create two new instances of Tiger
var tigerPawn = new Tiger();
var tigerKing = new Tiger();
// set the names of our tigers..
tigerPawn.setName('Tiger Pawn');
tigerKing.setName('Tiger King');
// coronate Tiger King!
tigerKing.coronate();
// get our names of things..
tigerPawn.getName(); // "Tiger Pawn, who is a nobody. "
tigerKing.getName(); // "Tiger King, who is the mother fucking King!"
tigerKing.name; // "Tiger King"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment