How to give an object public + private methods & properties

var VILLAGE = (function(){
  var locationOfGold = "under the tree"; //private
  var numberOfGoldBars = 1000;

  var addGoldToStore = function(){ };
  var moveGoldCache = function(){ };

  // everything above here is private

  return {
    performAttackDefences: function(){
      //here we would move our gold
    }
  };

})(); //note, immediately invoked function

Page created on 6 Jun 2020