Last active
September 30, 2022 01:23
-
-
Save reinaldorauch/60f02c07a6c8ac1c9137f64d964fb067 to your computer and use it in GitHub Desktop.
javascript classes versus functions
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
class Klass { | |
private _privProperty = 10; | |
printHelloTenTimes() { | |
for (let i = 0; i < this._privProperty; i++) { | |
console.log('Hello'); | |
} | |
} | |
} | |
const obj = new Klass(); | |
obj.printHelloTenTimes(); |
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
function Klass() { | |
const _privProperty = 10; | |
return { | |
printHelloTenTimes | |
}; | |
function printHelloTenTimes() { | |
for(let i = 0; i < _privProperty; i++) { | |
console.log('Hello'); | |
} | |
} | |
} | |
const obj = new Klass(); | |
obj.printHelloTenTimes(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment