The book I am learning from says the following code is creating an object, but I am unsure as to how this works. The second section of code is another way I have learned, from an online tutorial. But what is the difference? I have tried to research this myself but am quite new to all of this and some of the explanations I do not understand. Are there advantages/disadvantages to using each one? Thanks in advance.
function Player (name , score , rank)
{
this.name = name ;
this.score = score ;
this.rank = rank ;
}
var playerOne = new Player ( "Craig" , 199 , "1st" ) ;
The following is the way I had done it previously ;
var playerOne = {name: "Craig" , score: 199 , rank: "1st"} ;
var playerTwo = {name: "Tohny" , score: 155522 , rank: "2nd"} ;