Created
November 15, 2013 17:02
-
-
Save MorganConrad/7487819 to your computer and use it in GitHub Desktop.
Example of "classical" style JavaScript
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
module.exports = Foo; // just one line to get all of this code. | |
// Now how much would you pay? | |
/** constructor capital first letter to remind callers**/ | |
function Foo(args) { | |
if (!this instanceof Foo) // but callers do screw up... | |
return new Foo(args) // or, if you wish, throw something | |
this.useSoap = args.useSoap ; // define instance vars here | |
this.bar = {}; | |
} | |
// equivalent to static constants (ideally should be final) | |
Foo.CONSTANT1 = 'specialConstant'; | |
// static function, no "this" | |
Foo.function1 = function(args) { | |
... | |
} | |
// method, "this" is almost certainly a Foo | |
Foo.prototype.method1 = function(args) { | |
... | |
}; | |
// "hide" private method by convention of leading underscore | |
Foo.prototype._privatemethod1 = function(args) { | |
... | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment