Skip to content

Instantly share code, notes, and snippets.

@PieterScheffers
Created April 29, 2015 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PieterScheffers/8c66b8ea4aff1a22a6cb to your computer and use it in GitHub Desktop.
Save PieterScheffers/8c66b8ea4aff1a22a6cb to your computer and use it in GitHub Desktop.
Javascript - Class
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