Created
September 28, 2015 19:03
-
-
Save cferdinandi/74a2bdd806b80c0aa8ba to your computer and use it in GitHub Desktop.
Prototypal inheritance boilerplate via @toddmotto...
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
// 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