Created
          November 2, 2013 15:57 
        
      - 
      
 - 
        
Save tmccombs/7280357 to your computer and use it in GitHub Desktop.  
    A method to create a truly private method in Javascript
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var MyClass; | |
| function() { | |
| MyClass = function() { | |
| this.prop = {}; | |
| } | |
| //private method | |
| function getProp() { | |
| return this.prop; | |
| } | |
| //public method | |
| MyClass.prototype.foo = function() { | |
| return "foo " + getProp.call(this); //how to call the private method. | |
| } | |
| } | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment