mixing directly into an array? · Issue #4 · component/enumerable · GitHub
Skip to content

mixing directly into an array? #4

Open

Description

@matthewmueller

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' ]

Activity

  1. tj commented on Nov 8, 2012

    @tj
    Member

    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

  2. matthewmueller commented on Nov 8, 2012

    @matthewmueller
    MemberAuthor

    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.

  3. tj commented on Nov 8, 2012

    @tj
    Member

    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

  4. tj commented on Nov 8, 2012

    @tj
    Member

    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 :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions