enumerable
enumerable copied to clipboard
mixing directly into an array?
It'd be really sweet to be able to do something like this:
var users = [];
enumerable(users);
var matt = {
name : 'matt',
age : 23
};
var jim = {
name : 'jim',
age : 42
};
users.push(matt, jim);
var names = users.map('name') // [ 'matt', 'jim' ]
users = enumerable(users) will work, I do this in the tests a lot, returns an Enumerable with the array as .obj as a wrapper. the wrapper is for the same reason as Emitter, more efficient than doing a one-of mixin
Hmm, do you happen to have any stats/links on performance differences?
In this example you'd have to do users.value().push(matt, jim); which is something found really annoying about working with backbone's collections.
i havent bothered to benchmark it but it's a large difference considering you're adding one prop, or adding ~40 each time and v8 can't inline the lookups etc.
yeah it's definitely annoying, prototypes and inheritance are very flawed at best, we could maybe have a higher-level enumerable array thing that just hides the array inside but still has .push etc, kinda like https://github.com/component/collection/blob/master/index.js
unfortunately with how js is structured you more or less cannot cleanly extend things, just a language-level flaw, but almost every language does the same dumb things :(