Created
          April 29, 2015 13:38 
        
      - 
      
 - 
        
Save PieterScheffers/8c66b8ea4aff1a22a6cb to your computer and use it in GitHub Desktop.  
    Javascript - Class
  
        
  
    
      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 Person = (function() { | |
| var persons = []; // class variable | |
| function Person(name) { | |
| this.name = name; // normal instance variable | |
| this._password = "secret"; // poor-mans private variable | |
| } | |
| Person.prototype.sayHello = function() { // instance method | |
| var _this = this; // save 'this' for callback functions | |
| // save 'this' with 'private' _this | |
| var callbackResult = (function(_this) { | |
| return callbackFunc(function() { | |
| _this.name = ""; | |
| }); | |
| })(this); | |
| }; | |
| Person.personsCount = function() { // class method | |
| return persons.length; | |
| }; | |
| return Person; | |
| }(); | |
| var person = new Person("Klaas"); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment