Skip to content

Instantly share code, notes, and snippets.

@joechan3
Created April 23, 2016 04:46
Show Gist options
  • Save joechan3/b8365cbba60803cd30c1d8c4c3e5301d to your computer and use it in GitHub Desktop.
Save joechan3/b8365cbba60803cd30c1d8c4c3e5301d to your computer and use it in GitHub Desktop.
Prototype Example from Lynda: JavaScript Essential Training
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="mainContent">
<h1>Prototype Example</h1>
</div>
<script src="script.js"></script>
</body>
</html>
// Simple prototype example
function Player(n,s,r) {
this.name = n;
this.score = s;
this.rank = r;
}
Player.prototype.logInfo = function() {
console.log("I am:" , this.name);
}
Player.prototype.promote = function() {
this.rank++;
console.log("My new rank is: " , this.rank);
}
var fred = new Player("Fred",10000,5);
fred.logInfo();
fred.promote();
var bob = new Player("Bob",50,1);
bob.logInfo();
bob.promote();
var jane = new Player("Jane",50000,10);
jane.logInfo();
jane.promote();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment