Skip to content

Instantly share code, notes, and snippets.

@daftspunk
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save daftspunk/6fda3cedb8b5edba9871 to your computer and use it in GitHub Desktop.

Select an option

Save daftspunk/6fda3cedb8b5edba9871 to your computer and use it in GitHub Desktop.
JS Class Boilerplate
/*
* 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