Last active
August 26, 2015 04:38
-
-
Save cerebrl/94018245c72dd50495d1 to your computer and use it in GitHub Desktop.
Making a "class" in JavaScript. What we typically see when we code up the M in MVC.
This file contains 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
/** **************************************** | |
* Constructor for say hi feature. | |
* @constructor SayHiConstructor | |
* @returns {object} | |
*/ | |
function SayHiConstructor() { | |
this.greeting = "Basic module says, 'hallo'!" | |
} | |
SayHi.prototype.sayHi = function sayHi() { | |
this.writeToConsole()); | |
} | |
SayHi.prototype.writeToConsole = function writeToConsole() { | |
console.log(this.greeting); | |
} | |
// module.exports = SayHiConstructor; | |
/** | |
* Pros: memory effecient for programs | |
* Cons: dependency on implicit environment, no privates, more complex mental model, | |
* mutable properties | |
* | |
* Gang of Four says ... | |
* 1) "Program to an 'interface', not an 'implementation'." | |
* 2) "Favor 'object composition' over 'class inheritance'." | |
* | |
* This method does not normally adhere to these principles | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment