Skip to content

Instantly share code, notes, and snippets.

@svapreddy
Created April 27, 2014 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svapreddy/11339370 to your computer and use it in GitHub Desktop.
Save svapreddy/11339370 to your computer and use it in GitHub Desktop.
// Author : Prathap Reddy SV
// Purpose : Show an Example of the code structure I use.
var Example = (function($, document, window, undef){
// Bake your Object inside.
function Example(a, b){
this.a = a === undef ? 0 : a;
this.b = b === undef ? 0 : b;
}
// Private
function examplePrivate(a){
return a;
}
// Public
Example.prototype.method1 = function(){
var that = this;
return examplePrivate(that.a);
}
Example.prototype.method2 = function(){
// Do something
}
return Example;
})(window.jQuery || window.Zepto, document, window);
// Then initialize like below
var ex1 = new Example(10, 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment