Created
March 9, 2016 11:12
-
-
Save qgp9/c64758dadd27273c7545 to your computer and use it in GitHub Desktop.
idea of strict class template like C++
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' | |
/*================ Requires =====================================*/ | |
//let utils = require( './utils' ); | |
/*================ Class Variables/Constants ====================*/ | |
let methods ; // Mandatory | |
const CODE_STRING = '<<code>>'; | |
let someClassVariable = 'someClassVariable'; | |
/*======================== Exports ========================*/ | |
module.exports = MyClass; | |
/*======================== Class ========================*/ | |
function MyClass( args ) { | |
if( !this ) return; | |
// Private Variables | |
let opts = 'opts'; // options | |
let somePrivateVarable1 = 'somePrivateVarable1'; | |
// Public Variables | |
let self = this; // Mandatory | |
self.options = 'options'; | |
self.somePublicVariable1 = 'somePublicVariable1'; | |
// Private function/medhod | |
// init(); | |
// parseAttrs(); | |
// Public Method | |
MyClass.prototype.anyMethod1 = anyMethod1InDifferentNameOfFunction; | |
// Object Init | |
console.log( "# Call init from MyClass" ); | |
init(); | |
// WorkFlow | |
console.log( "# Call init from MyClass" ); | |
parseAttrs(); | |
/*=================== function ===================*/ | |
function init () { | |
// Any init function | |
console.log( "=== init ===" ); | |
} | |
function parseAttrs(){ | |
console.log( "=== This is parseAttrs ===" ); | |
console.log( "# Call anyMethod1InDifferentNameOfFunction from parseAttrs" ); | |
anyMethod1InDifferentNameOfFunction(); | |
} | |
function anyMethod1InDifferentNameOfFunction(){ | |
console.log( "=== anyMethod1InDifferentNameOfFunction ===" ); | |
console.log('CODE_STRING = ' + CODE_STRING); | |
console.log('someClassVariable = ' + someClassVariable); | |
console.log('opts = ' + opts); | |
console.log('somePrivateVarable1 = ' + somePrivateVarable1); | |
console.log('self.options = ' + self.options); | |
console.log('self.somePublicVariable1 = ' + self.somePublicVariable1); | |
} | |
} | |
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' | |
/*================ Requires =====================================*/ | |
let MyClass = require( './myClass' ); | |
console.log( "########### make myClass1" ) | |
let myClass1 = new MyClass(); | |
myClass1.somePublicVariable1 = 'somePublicVariable1 of myClass1'; | |
console.log( myClass1.somePublicVariable1 ); | |
myClass1.anyMethod1(); | |
console.log( "########### make myClass2" ) | |
let myClass2 = new MyClass(); | |
myClass2.somePublicVariable1 = 'somePublicVariable1 of myClass2'; | |
console.log( myClass2.somePublicVariable1 ); | |
myClass2.anyMethod1(); | |
try { | |
myClass1.parseAttrs(); | |
} catch(e) { | |
console.log(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment