JS: revealing module pattern - accessing internal objects vs arrays?
问题 Using the revealing module pattern, how can I provide direct access to non-static private variables? Here's what I have: var M = function () { var obj = {}; var arr = []; var change = function () { obj = {"key":"if I see this, O is a reference to obj"}; arr.push("If I see this, A is a reference to arr") }; return { change: change, O: obj, A: arr }; }(); M.change(); console.log(M.A); // prints ["If I see this, A is a reference to arr"] console.log(M.O); // prints Object {}, wanted "if I see