Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardJavaScripthidden classes and inline cachesSingle-choice MCQ

In V8, assigning all of an object's properties inside the constructor (vs adding some after construction) matters for hidden classes. Why does the SECOND object below end up on a different, slower-to-optimize shape than the first?

function P(x, y) { this.x = x; this.y = y; } const a = new P(1, 2); const b = new P(1, 2); b.z = 3; // added after construction