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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -