Skip to main content

Timeline for Best practice javascript objects

Current License: CC BY-SA 3.0

7 events
when toggle format what by license comment
Jun 13, 2013 at 16:28 vote accept user1503606
Jun 13, 2013 at 15:54 comment added Benjamin Gruenbaum Are we really having a discussion on which is faster? Performance would be meaningless in this case (Or do you intend to run over 30K arrays with 100 elements through it every second?). If you're worried about performance, all three options are very slow compared to a native loop by at least a factor of 10.
Jun 13, 2013 at 15:49 comment added Joseph @BenjaminGruenbaum Point taken on the HTML string and code semantics. However, on the performance department, filter+map is slower due to the fact that it equates to running 2 nonbreaking loops, generating at least 2 more objects as seen in this test (Firefox24 and Chromium25 seem to agree).
Jun 13, 2013 at 15:16 comment added Benjamin Gruenbaum I've always viewed the fact you can break an each by returning false as a bug in the implementation. It was considered, and rejected in the spec when building native .map. If you're filtering and then mapping, consider using .filter and then .map. I think it represents the actual action done much better. Also, feedTemplate is not just a string, it's an HTML string. Storing HTML strings in code means not separating your view from your view model, which can get really sucky as you scale.
Jun 13, 2013 at 15:12 comment added Joseph @BenjaminGruenbaum Nice point. But I used a string instead to represent the fact that it is a string. One can easily use .html() to pull it out from the HTML, or use AJAX if the template is from another file later on. Also, I think $.each() would be better since return false will break the loop. In $.map(), you can return null to remove the item, but the loop will still run through the entire collection.
Jun 13, 2013 at 14:56 comment added Benjamin Gruenbaum I would probably have the model pull the view from the HTML (for example from a <template> tag, or a <script type='template/Mustache>) rather than store it as a string template. Other than that, I think this solution is very nice and solves most of the problems OP's code has. That $.each` could have been a $.map.
Jun 13, 2013 at 14:23 history answered Joseph CC BY-SA 3.0