I try to get private property from a module, but always get the initial value, not the latest.
When the form is submitted and the onSuccess call is called, I set partnerId = 10.
After that, I have a click event that gets the partner id and gets -1
search.js
var SearchForm = (function ($) { "use strict";
detail.js
var PartnerDetail = (function ($) { "use strict"; var _partnerId = -1; var getPartnerId = function () { return _partnerId; }; var setPartnerId = function (id) { _partnerId = id; }
search.internal.js
var SearchAll = (function ($) { "use strict"; // Private variables // Private functions var init = function () { $("#partner").on("click", function () { var p = PartnerDetail.getPartnerId(); console.log(p); ==> -1 } }; // Public functions return { init: init }; })(jQuery);
(main page)
// Load when ready $(document).ready(function () { SearchAll.init(); });
source share