Last active
April 18, 2024 15:34
-
-
Save blackakula/e2bf38bc7d1c540700b7e0c6c26f6c85 to your computer and use it in GitHub Desktop.
Classes versus co-data
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
| class ClassWhoAmI { | |
| #prefix = 'It is the secret' | |
| suffix = 'person' | |
| static additional = 'bad one' | |
| constructor(parameter) { | |
| this.parameter = parameter | |
| } | |
| getValue() { | |
| return `${this.#prefix}: ${this.parameter} ${this.suffix}` | |
| } | |
| } | |
| var testClassObject = new ClassWhoAmI("I'm") | |
| testClassObject.suffix = 'programmer' | |
| console.log(testClassObject.getValue(), '-', ClassWhoAmI.additional) |
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
| var DataWhoAmI = Object.assign((parameter) => { | |
| var prefix = 'It is the secret' | |
| var coData = { | |
| suffix: 'person', | |
| getValue: () => `${prefix}: ${parameter} ${coData.suffix}` | |
| } | |
| return coData | |
| }, {additional: 'good one'}) | |
| var testDataObject = DataWhoAmI("I'm") | |
| testDataObject.suffix = 'programmer' | |
| console.log(testDataObject.getValue(), '-', DataWhoAmI.additional) |
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
| function FuncWhoAmI(parameter) { | |
| this.suffix = 'person' | |
| this.parameter = parameter | |
| } | |
| FuncWhoAmI.additional = 'old one' | |
| FuncWhoAmI.prototype.getValue = function () { | |
| return `It can not be a secret: ${this.parameter} ${this.suffix}` | |
| } | |
| var testFuncObject = new FuncWhoAmI("I'm") | |
| testFuncObject.suffix = 'programmer' | |
| console.log(testFuncObject.getValue(), '-', FuncWhoAmI.additional) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment