Created
June 11, 2013 13:49
-
-
Save tomgullo/5757005 to your computer and use it in GitHub Desktop.
javascript_prototype_testing.js
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 G(name, names) { | |
this.name = name; | |
this.players = {}; | |
for (i=0; i < names.length; i++) { | |
this.players[ names[i] ] = {}; | |
} | |
} | |
G.prototype = { | |
deal: function() { | |
for (i in this.players) { | |
var player = this.players[i] | |
player.cards = 5; | |
} | |
}, | |
showCards: function() { | |
console.log('\n\nGame ' + this.name); | |
for (i in this.players) { | |
var player = this.players[i] | |
console.log( i + ' is showing cards ' + player.cards ); | |
} | |
} | |
} | |
var g = new G('game 1', ['tom', 'george']) | |
g.deal() | |
g.showCards() | |
console.log('done'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment