KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How would I go about implementing python's namedtuple in javascript? Ideally I would also want a function I could "map" over a sequence of sequences to turn it into a sequence of namedtuple-like objects. // with underscore.js included... var points = [[1,2], [3,4], [4,5] var Point = namedlist('Point', 'x y') points = _.map(Point._make, points) point1 = points[0] var x = point1.x var y = point1.y Note that I don't want to have to code a new class like "Point" every time, but instead would like a factory function that produces a new class supporting list item access with the given field names. Side note: an assumption underlying this question is that javascript maps use less memory that lists. Is that assumption reasonable?
Tags (comma-separated)
Save Edits
Cancel