Created
July 18, 2014 13:16
-
-
Save CharlotteGore/a6ee30b00eadd363da56 to your computer and use it in GitHub Desktop.
Very basic Javascript
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
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