Edit in JSFiddle

CalcModule = (function(){
                        var pub = {};
                        var mem = new Array(); //private variable
                        
                        var storeInMemory = function(val){ //private function
                                                mem.push(val);
                                            };
                        
                        pub.add = function(a,b){ 
                                     var result = a + b;
                                     storeInMemory(result); //calling private function
                                     return result;
                                  };

                       pub.sub = function(a,b){
                                     var result = a - b;
                                     storeInMemory(result); //call to private function
                                     return result;
                                  };

                       pub.retrieveFromMemory = function(){
                                     return mem.pop();
                       };

                       return pub;
})();
1. Click to Add 2, 10 and Store result on calculator's stack : <button onclick="CalcModule.add(2,10);">Add 2,10</button><br>
2. Click to Add 5, 15 and Store result on calculator's stack : <button onclick="CalcModule.add(5,15);">Add 5,15</button><br>
3. Cilck to alert the stack's poped value:
<button onclick="alert(CalcModule.retrieveFromMemory());">Pop Stack</button><br>