Skip to content

Instantly share code, notes, and snippets.

@Makio64
Last active August 29, 2015 14:05
Show Gist options
  • Save Makio64/3a684306445dc96aa048 to your computer and use it in GitHub Desktop.
Save Makio64/3a684306445dc96aa048 to your computer and use it in GitHub Desktop.
JS Class template / best practice
'use strict';
/**
* MyClass
*
* @class MyClass
* @author David Ronai http://makiopolis.com/ @Makio64
*/
// --------------------------------------------------------------------------- CONSTRUCTOR
LIB.MyClass = function(myPropertie)
{
LIB.BaseClass.call( this );
// define a propertie with a default value
this.myPropertie = props || 0;
};
LIB.MyClass.prototype = Object.create( LIB.BaseClass.prototype );
LIB.MyClass.prototype.constructor = LIB.MyClass;
// --------------------------------------------------------------------------- METHODS
LIB.MyClass.prototype.myMethod = function(args)
{
// do something..
return;
}
// --------------------------------------------------------------------------- GETTERS & SETTERS
Object.defineProperty(LIB.MyClass.prototype, 'myPropertie', {
get: function() {
return this.myPropertie;
},
set: function(value) {
return this.myPropertie = value;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment