Skip to content

Instantly share code, notes, and snippets.

@Aschen
Created January 22, 2024 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aschen/0a03131eda3b9e1f597b509b951a4927 to your computer and use it in GitHub Desktop.
Save Aschen/0a03131eda3b9e1f597b509b951a4927 to your computer and use it in GitHub Desktop.
Method vs member holding a function
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