JavaScript Module - Count

JavaScript Module - Count

by Nirvanachain

HTML

<!-- Helpful URL:
http://javascriptplayground.com/blog/2012/04/javascript-module-pattern/
-->

JavaScript

var Jspy = (function() {
    var _count = 0;  //underscore denotes private variable
    
    var incrementCount = function() {
        _count++;   
    }
    
    var getCount = function() {
        return _count;   
    }
    
    return {
        incrementCount : incrementCount,
        getCount       : getCount
    }
    
})();

console.log( Jspy.getCount() ); //get the value of _count
Jspy.incrementCount(); //increment the value of _count
console.log( Jspy.getCount() );  //get the new value of _count