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
  • 155,085
  • 27
  • 166
  • 222
gigi
  • 3,596
  • 7
  • 36
  • 48

1 Answers1

1

The variable state is available anywhere inside usersController

Try:

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

DEMO

charlietfl
  • 169,044
  • 13
  • 113
  • 146