Why using the size property in set

# Maxime Warnier (11 years ago)

I was reading the doc for the new Set method and something suprised me :

Why Set uses the size method instead of the length property ?

# David Bruant (11 years ago)

IIRC and with my own words "length" refers more to something that can be measured contiguously (like a distance or a number of allocated bytes, etc.) while "size" doesn't have this contiguous aspect to it.

# Nathan Wall (11 years ago)

Also, whether this was intentional or not, I think it's nice for objects with length properties to all have properties at indices from 0 to length (so they work in the Array.prototype methods) making 'length' in foo a lazy-man's isArrayLike.

var forEach = Function.prototype.call.bind(Array.prototype.forEach);
forEach('foo', function(u) {
    console.log(u);
});
# Allen Wirfs-Brock (11 years ago)

This was intentional

# Maxime Warnier (11 years ago)

yes in fact it makes sens because Set.length is the property of Set, not necessary the length of the collection.

Thanks for your answers :)