javascript - How to change a parameter inside an object? -


begginer here.

var player() = { isdrunk: false } 

how set isdrunk true after player uses item "beer"? (completely made-up example)

to answer question player.isdrunk = true

so have

var player = {   lefthanded: false,   righthanded: true,   isdrunk: false  }; 

and then

  function drinkbeer(player) {       player.isdrunk = true;  } 

then can pass players drinkbeer function needed. alternatively can put function inside player object if want each individual player have drinkbeer() function can use change own isdrunk property calling player.drinkbeer()

that this:

var player = {   lefthanded: false,   righthanded: true,   isdrunk: false,   drinkbeer: function() {         isdrunk = true;      }  }; 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -