Difference between revisions of "JS - How to define a Javascript Class"

From GUILLARD WIKI
Jump to navigation Jump to search
(Created page with "<code> <script> function minivileClass(){ // # Variables this.message = "Welcome on the amazing JS world !"; this.cards = [ {number:"1",colorRule:"blue",actionRule:"+...")
 
Line 1: Line 1:
<code>
<script>
<script>


Line 48: Line 46:
</fieldset><br/>
</fieldset><br/>
</body>
</body>
</code>

Revision as of 15:58, 14 November 2016

<script>

function minivileClass(){

// # Variables this.message = "Welcome on the amazing JS world !"; this.cards = [ {number:"1",colorRule:"blue",actionRule:"+1piece",label:"Champs de ble",price:"1"}, {number:"2-3",colorRule:"green",actionRule:"+1piece",label:"Boulangerie",price:"1"}, {number:"3",colorRule:"red",actionRule:"-1pieceToCurrentPlayer",label:"Cafe",price:"2"}, {number:"5",colorRule:"blue",actionRule:"+1piece",label:"Foret",price:"3"}, {number:"6",colorRule:"violet",actionRule:"+2piecesFromOtherPlayers",label:"Stade",price:"6"} ]; // # Variables

// # Constructor

   if(typeof minivileClass.initialized == "undefined"){ 

// # Functions minivileClass.prototype.newGame = function(){ alert(this.message);

       };

minivileClass.prototype.updateHtml = function(){ for (var i in this.cards) document.getElementById("allCards").innerHTML = document.getElementById("allCards").innerHTML + ''+this.cards[i]['number']+" "+this.cards[i]['label']+""; }; // # Functions

       minivileClass.initialized = true; 
   }

// # Constructor }

window.onload = function(){ var game = new minivileClass(); game.newGame(); game.updateHtml(); }

</script>

<body> <fieldset><legend>Available cards</legend> </fieldset>
</body>