Created
February 1, 2013 14:56
-
-
Save mlconnor/4691783 to your computer and use it in GitHub Desktop.
Javascript Notes
This file contains 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
// ==== 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