title: How do I assign a function to the property of a Javascript object?
body: <p>I was looking and struggling to the following example:</p>
  
  <pre><code>var player1= {name: "Chris", score: 1000, rank: 1};
  var player2= {name: "Kristofer", score: 100000, rank: 2};
  
  function playerDetails(){
  alert("The name of the player is "+ this.name + "."+ " His score is : "+ this.score + "and his rank : "+ this.rank);
  }
  player1.logDetails= playerDetails;
  player2.logDetails= playerDetails;
  
  player1.logDetails();
  player2.logDetails();
  </code></pre>
  
  <p>As far as I know <code>player1.logDetails</code> is a property of player1 or a method of player1.
  So I can't understand how the author assigns a property to a function. 
  Also I don't get why you would write it like that instead of : 
      player1.logDetails= playerDetails();
  which I have tried and doesn't work. </p>
  
  <p>Then he calls <code>player1.logDetails()</code> which is a function but not declared anywhere.(?)</p>
  
  <p>If anyone could help??
  Thank you in advance</p>