Skip to content

Instantly share code, notes, and snippets.

@mlconnor
Created February 1, 2013 14:56
Show Gist options
  • Save mlconnor/4691783 to your computer and use it in GitHub Desktop.
Save mlconnor/4691783 to your computer and use it in GitHub Desktop.
Javascript Notes
// ==== DOING CLASSES IN JS ============================================/
// constructor function
function MyClass () {
var privateVariable; // private member only available within the constructor fn
this.privilegedMethod = function () { // it can access private members
//..
};
}
// A 'static method', it's just like a normal function
// it has no relation with any 'MyClass' object instance
MyClass.staticMethod = function () {};
MyClass.prototype.publicMethod = function () {
// the 'this' keyword refers to the object instance
// you can access only 'privileged' and 'public' members
};
var myObj = new MyClass(); // new object instance
myObj.publicMethod();
MyClass.staticMethod();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment