question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why not use JavaScript getters?

See original GitHub issue

I’m not sure if I’m overlooking something or if this is a stupid question, but… Why not use JavaScript getters?

JavaScript objects have support for getters: (works everywhere except on IE8)

Why not use them (optionally) instead of .get() and .getIn()? Especially for server-side code and for applications that aren’t focusing IE8 this could be really helpful.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:5
  • Comments:11

github_iconTop GitHub Comments

4reactions
scottmascommented, Sep 19, 2017

FWIW, Object.defineProperty is now just as fast as getting/setting via methods. https://jsperf.com/getter-setter/8

1reaction
Tvarohcommented, Jul 31, 2014

@JannesMeyer AFAIK they are terribly slow. I saw a benchmark (can’t find the link at the moment) and they were 10 times slower than usual approach.

Read more comments on GitHub >

github_iconTop Results From Across the Web

why should not use getters/setters? #1880 - GitHub
Getters and setters are intended to hide computational functionality. They are made specifically so you wouldn't know if the value is computed.
Read more >
Are `getter` and `setter` necessary in JavaScript?
A getter has use when you want to run some code every time a property is requested. In your example, the getter always...
Read more >
Be careful with JavaScript getters and setters | by Kesk
Since you reference the property person.age, JavaScript needs to get that property. When this happens, the getter is triggered. JavaScript calls the getter,...
Read more >
No, Getters and Setters in TypeScript & JavaScript aren't useless
In this blog post, we talk about the utility of getters and setters in modern web development. Are they useless? When does it...
Read more >
Why getters/setters is a bad idea in JavaScript
You're right that detecting typos is a problem, but the cause isn't setters and getters – it's Javascript's lack of static types. If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found