Last active
August 29, 2015 14:05
-
-
Save Makio64/3a684306445dc96aa048 to your computer and use it in GitHub Desktop.
JS Class template / best practice
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
'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