Reading up on V8 (micro) optimization from this old article and there is a quote:
Always initialize object members in the same order
Question: In the example below, what does it mean to Always initialize object members in the same order?
function Point(x, y) {
this.x = x; // this.x = x line first because x is the first arg
this.y = y; // this.y = y line second because y is the second arg
}
var p1 = new Point(11, 22);
var p2 = new Point(33, 44);
// At this point, p1 and p2 have a shared hidden class
p2.z = 55;
// warning! p1 and p2 now have different hidden classes!
Longer quote:
JavaScript has limited compile-time type information: types can be changed at runtime, so it's natural to expect that it is expensive to reason about JS types at compile time. This might lead you to question how JavaScript performance could ever get anywhere close to C++. However, V8 has hidden types created internally for objects at runtime; objects with the same hidden class can then use the same optimized generated code.
Until the object instance p2 has additional member ".z" added, p1 and p2 internally have the same hidden class - so V8 can generate a single version of optimized assembly for JavaScript code that manipulates either p1 or p2. The more you can avoid causing the hidden classes to diverge, the better performance you'll obtain.
Therefore:
Initialize all object members in constructor functions (so the instances don't change type later)
Always initialize object members in the same order
Note: I've found similar questions in C++ but I cant really read it Why should I initialize member variables in the order they're declared in?