Last active
August 29, 2015 14:05
-
-
Save daftspunk/6fda3cedb8b5edba9871 to your computer and use it in GitHub Desktop.
JS Class Boilerplate
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
| /* | |
| * Example class | |
| * | |
| * Dependences: | |
| * - Some other plugin (filename.js) | |
| */ | |
| +function ($) { "use strict"; | |
| var ExampleClass = function () { | |
| // Init | |
| this.init() | |
| } | |
| ExampleClass.prototype.init = function() { | |
| // Shared properties | |
| this.$someThing = $('#someThing') | |
| /* | |
| * Bind event handlers | |
| */ | |
| $(document).on('open.oc.example', '.some-element', $.proxy(this.openSomeElement, this)) | |
| } | |
| ExampleClass.prototype.someFunction = function() { | |
| // Do stuff | |
| } | |
| ExampleClass.prototype.openSomeElement = function(e) { | |
| var self = this, | |
| $item = $(e.relatedTarget) | |
| return false | |
| } | |
| $oc.exampleClass = ExampleClass; | |
| $(document).ready(function(){ | |
| new $oc.exampleClass | |
| }) | |
| }(window.jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment