如何在删除确认功能中访问私有变量“state”。 “this”关键字将我指向窗口对象。
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
};
}());
我称之为:
$(function() {
usersController.init({
urls: {
deleteRecord: "...."
}
});
});
答案 0 :(得分:1)
变量state
可在usersController
尝试:
showDeleteConfirmation = function(recordId) {
console.log(state);
};
的 DEMO 强>