Skip to content

Instantly share code, notes, and snippets.

@cferdinandi
Created September 28, 2015 19:03
Show Gist options
  • Save cferdinandi/74a2bdd806b80c0aa8ba to your computer and use it in GitHub Desktop.
Save cferdinandi/74a2bdd806b80c0aa8ba to your computer and use it in GitHub Desktop.
Prototypal inheritance boilerplate via @toddmotto...
// IIFE, or any type of wrapper to export
var newModule = (function () {
// non-instance private vars
var someVar;
// @constructor
function MyConstructor(elem, options) {
var defaults = {};
this.elem = elem;
this.options = options; // do some extend or whatever with "defaults"
}
function doSomething() {
// do something, obviously...
console.log('doing something!');
}
function doAnotherThing() {
// do another thing, obviously...
}
MyConstructor.prototype.doSomething = doSomething;
MyConstructor.prototype.doAnotherThing = doAnotherThing;
return function (elem, options) {
return new MyConstructor(elem, options);
};
})();
var instance = newModule('.elem', {
// config Object block
});
instance.doSomething();
instance.doAnotherThing();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment