You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: