Created
January 22, 2024 17:24
-
-
Save Aschen/0a03131eda3b9e1f597b509b951a4927 to your computer and use it in GitHub Desktop.
Method vs member holding a function
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 Foobar { | |
private name = 'foobar' | |
getName = () => { | |
return this.name | |
} | |
} | |
class Barfoo { | |
private name = 'barfoor' | |
getName() { | |
return this.name | |
} | |
} | |
console.log(new Foobar()) | |
// Foobar { name: 'foobar', getName: [Function (anonymous)] } | |
console.log(new Barfoo()) | |
// Barfoo { name: 'barfoo' } | |
console.log(Object.keys(new Foobar())) | |
// [ 'name', 'getName' ] | |
console.log(Object.keys(new Barfoo())) | |
// [ 'name' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment