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
Post a Comment