Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set all object fields in the constructor instead of the prototype #2892

Closed
samelhusseini opened this issue Aug 21, 2019 · 1 comment
Closed
Labels
component: performance internal External contributions not accepted

Comments

@samelhusseini
Copy link
Contributor

The Google JS style guide says to set all concrete object fields (i.e. all properties other than methods) in the constructor as opposed to placing them on the prototype. see.

The style guide sites the reason being a performance gain. Looking more into this, the performance gain comes from engines (such as V8) optimizing for the shape of the object that it gets from what the constructor instantiates.

I had a chat to Neil and he ran some performance tests and found that there was a performance improvement on V8, but the two had very similar performance on Firefox.
I then ran the test myself on Safari, and found that there was a performance improvement on Safari as well.

Because of this, moving forward all new concrete object fields (ie: all properties other than methods) should go in the constructor.

@BeksOmega
Copy link
Collaborator

No longer an issue now that we've moved to typescript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: performance internal External contributions not accepted
Projects
None yet
Development

No branches or pull requests

2 participants