1

How to access private variable "state" in the delete confirmation function. The "this" keyword points me to the window object.

var usersController = (function() {
  var state = {},

    init = function(defaultState) {
      state = defaultState;

      $(".btn-delete-row").on("click", function() {
        var recordId = $(this).attr("data-record-id");
        showDeleteConfirmation(recordId);
      });
    },

    showDeleteConfirmation = function(recordId) {
      //how to access state private variable here???
    };

  return {
    init: init
  };
}());

and I call it like this:

$(function() {
  usersController.init({
    urls: {
      deleteRecord: "...."
    }
  });
});
mplungjan
  • 169,008
  • 28
  • 173
  • 236
gigi
  • 3,846
  • 7
  • 37
  • 50

1 Answers1

1

The variable state is available anywhere inside usersController

Try:

showDeleteConfirmation = function(recordId) {
      console.log(state);
};

DEMO

charlietfl
  • 170,828
  • 13
  • 121
  • 150