My question is a follow-up to this one: Clearing up the `hidden classes` concept of V8
Suppose I have the following JavaScript code:
var values1 = [ 1, 2, 3, 4];
var values2 = [ 5, 6, 7, 8];
var fields = [ "f1", "f2", "f3", "f4" ];
function Construct (fields, values) {
var i;
for (i = fields.length - 1; i >= 0; --i) this [fields [i]] = values [i];
}
var a = new Construct (fields, values1);
var b = new Construct (fields, values2);
Then, will a
and b
end up having the same hidden class?
The background of this question is that, to me, this seems the only possibility to make use of the "hidden class" optimization if the property names are not known at programming time.
Practical relevance: Suppose you write an application dealing with tabular data where the names of the columns are dynamic (not known at programming time). Then the rows of the table semantically share the same class, yet if the engine does not optimize, you will better use an array and do the "column name -> index" conversion manually in your code (which may make the code ugly, as you have to cache indices).