Skip to content

Instantly share code, notes, and snippets.

@SparK-Cruz
Last active September 29, 2015 07:57
Show Gist options
  • Select an option

  • Save SparK-Cruz/1570177 to your computer and use it in GitHub Desktop.

Select an option

Save SparK-Cruz/1570177 to your computer and use it in GitHub Desktop.
JavaScript Class boilerplate
/**
* JavaScript Class Definition
*
* Author: Roger "SparK" Rodrigues da Cruz
* Licence: Free, no credits, no references, just use it if you feel like.
*/
;MyClass = (function(){
var C = function(){ return constructor.apply(this,arguments); }
var p = C.prototype;
//list the attributes
p.name;
//construct
function constructor(name){
this.name = name;
}
//define methods
p.askName = function(){
return "Hello, my name is "+this.name;
}
//unleash your class
return C;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment