Skip to content

Instantly share code, notes, and snippets.

@tomgullo
Created June 11, 2013 13:49
Show Gist options
  • Save tomgullo/5757005 to your computer and use it in GitHub Desktop.
Save tomgullo/5757005 to your computer and use it in GitHub Desktop.
javascript_prototype_testing.js
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