Imagine we define a new object like this:
const foo = {number1: 1, number2: 2}
This should define a new "Hidden Class" with these two properties.
Now imagine I define a new class using ES6 class syntax.
class Numbers {
constructor() {
this.number1 = 1
this.number2 = 2
}
}
and I create a new object from it.
const bar = new Numbers()
Now the question: Is the "Hidden Class" of the bar
going to be the same as the Hidden Class of foo
?
Because what I imagine is going on is that the first definition will create a new "Hidden Class" with two properties but the second will create a new "Hidden Class" then it will create a new "Hidden Class" with one property and then create yet another "Hidden Class" with yet another property resulting in three "Hidden Classes" linked together.
Can somebody clarify that? If my assumptions are right then the new "ES6 class syntax" is indeed slower.
Based on the article: JavaScript engine fundamentals: Shapes and Inline Caches ยท Mathias Bynens