Skip to content

Instantly share code, notes, and snippets.

@kapv89
Last active December 17, 2015 00:29
Show Gist options
  • Select an option

  • Save kapv89/5521065 to your computer and use it in GitHub Desktop.

Select an option

Save kapv89/5521065 to your computer and use it in GitHub Desktop.
OOP in JS without "this" and "new" shit
//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