Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
  <head>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
    <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?skin=sons-of-obsidian"></script>
    <meta charset=utf-8 />
    <title>JS Bin</title>
  </head>
  <body>
    <h2>Closure Object Public/Private Methods Example</h2>
    <pre class="prettyprint linenums">
/*
 * Object: makeCounter
 * Public Methods: increment,decrement,value
 * Private Methods: changeVal
 */
var makeCounter = function() {
  var privateCounter = 0;
  function changeBy(val) {
    privateCounter += val;
  }
  return {
    increment: function() {
      changeBy(1);
    },
    decrement: function() {
      changeBy(-1);
    },
    value: function() {
      return privateCounter;
    }
  }  
};
var counter = makeCounter();
</pre>
    <h2>Closure </h2>
    <pre class="prettyprint linenums">
    </pre>
  </body>
</html>
  
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
kizzlebotpro
0viewers