Last active
December 17, 2015 00:29
-
-
Save kapv89/5521065 to your computer and use it in GitHub Desktop.
OOP in JS without "this" and "new" shit
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
| //class definition + constructor | |
| function FooFactory(bar, baz) { | |
| /* return an object with a set of properties and functionalities | |
| tied together using closuers and lexical scoping */ | |
| } | |
| // actual object construction | |
| var foo = FooFactory(bar, baz); | |
| //inheritance (via as many object as you want) | |
| function BarFactory(bar, baz, foo) { | |
| var foo = FooFactory(bar, baz); // use this provide foo's functionality inside bar objects | |
| // rest of bar's definition | |
| return bar; | |
| } | |
| // if need be, just attach a property named __factory = whatever-factory-constructs-the-object | |
| // static stuff | |
| FooFactory.stuff = function () { ... } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment