{"action":"created","issue":{"url":"https://api.github.com/repos/jashkenas/backbone/issues/4061","repository_url":"https://api.github.com/repos/jashkenas/backbone","labels_url":"https://api.github.com/repos/jashkenas/backbone/issues/4061/labels{/name}","comments_url":"https://api.github.com/repos/jashkenas/backbone/issues/4061/comments","events_url":"https://api.github.com/repos/jashkenas/backbone/issues/4061/events","html_url":"https://github.com/jashkenas/backbone/pull/4061","id":166700725,"number":4061,"title":"Implements the JavaScript Iterable protocol.","user":{"login":"leebyron","id":50130,"avatar_url":"https://avatars.githubusercontent.com/u/50130?v=3","gravatar_id":"","url":"https://api.github.com/users/leebyron","html_url":"https://github.com/leebyron","followers_url":"https://api.github.com/users/leebyron/followers","following_url":"https://api.github.com/users/leebyron/following{/other_user}","gists_url":"https://api.github.com/users/leebyron/gists{/gist_id}","starred_url":"https://api.github.com/users/leebyron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leebyron/subscriptions","organizations_url":"https://api.github.com/users/leebyron/orgs","repos_url":"https://api.github.com/users/leebyron/repos","events_url":"https://api.github.com/users/leebyron/events{/privacy}","received_events_url":"https://api.github.com/users/leebyron/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-20T22:50:44Z","updated_at":"2016-07-21T01:26:18Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/jashkenas/backbone/pulls/4061","html_url":"https://github.com/jashkenas/backbone/pull/4061","diff_url":"https://github.com/jashkenas/backbone/pull/4061.diff","patch_url":"https://github.com/jashkenas/backbone/pull/4061.patch"},"body":"This introduces new methods related to Iterators on Backbone.Collection to mirror those found on Array: `values`, `keys`, `entries`, and `@@iterator`. Each of these methods will return a JavaScript Iterator, which has a `next` method, yielding the models or ids of models contained in the Collection.\r\n\r\nThe CollectionIterator is careful to use the `at()` and `modelId()` methods on the host collection rather than direct access to the `models` property, which should ensure it is resilient to creative subclassing of Backbone.Collection and future feature addition.\r\n\r\nCollectionIterator's `next` method follows the same [algorithm defined by ES6 for ArrayIterator's `next`](http://www.ecma-international.org/ecma-262/6.0/#sec-%arrayiteratorprototype%.next).\r\n\r\nThe [`@@iterator`](http://www.ecma-international.org/ecma-262/6.0/#sec-well-known-symbols) method is defined using `Symbol.iterator` if it exists in the JavaScript runtime (modern browsers/node.js) and falls back to the string `\"@@iterator\"` which was popularized by older versions of Firefox and has become the standard fallback behavior for other third-party libraries. This ensures that Backbone can still be used across all browsers, even with use of these new methods.\r\n\r\nSupporting Iterable allows better integration between Backbone and the most recent additions to the JavaScript language, including `for of` loops and data-collection constructor functions, as well as better integration with other third-party libraries that accept Iterables instead of only Arrays.\r\n\r\nFixes #3954"},"comment":{"url":"https://api.github.com/repos/jashkenas/backbone/issues/comments/234131893","html_url":"https://github.com/jashkenas/backbone/pull/4061#issuecomment-234131893","issue_url":"https://api.github.com/repos/jashkenas/backbone/issues/4061","id":234131893,"user":{"login":"leebyron","id":50130,"avatar_url":"https://avatars.githubusercontent.com/u/50130?v=3","gravatar_id":"","url":"https://api.github.com/users/leebyron","html_url":"https://github.com/leebyron","followers_url":"https://api.github.com/users/leebyron/followers","following_url":"https://api.github.com/users/leebyron/following{/other_user}","gists_url":"https://api.github.com/users/leebyron/gists{/gist_id}","starred_url":"https://api.github.com/users/leebyron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leebyron/subscriptions","organizations_url":"https://api.github.com/users/leebyron/orgs","repos_url":"https://api.github.com/users/leebyron/repos","events_url":"https://api.github.com/users/leebyron/events{/privacy}","received_events_url":"https://api.github.com/users/leebyron/received_events","type":"User","site_admin":false},"created_at":"2016-07-21T01:26:18Z","updated_at":"2016-07-21T01:26:18Z","body":"That's definitely a concern to weigh. I'm curious to know more about the issues Ramda encountered. I would be surprised if `Object.keys()` presented an issue, since that's a pretty uncommon operation in general on a Backbone.Collection but even if it was performed, it should not include the properties of the Collection.prototype (unless of course you're calling `Object.keys()` directly on Collection.prototype). If this is a serious concern, we could use `Object.defineProperty` instead to ensure it is non-enumerable.\r\n\r\nAnother potential approach to avoid inconsistency is to *always* define `Collection.prototype[\"@@iterator\"]` while only defining `Collection.prototype[Symbol.iterator]` should `Symbol.iterator` be defined.\r\n\r\nAn unfortunate issue of only implementing Iterable when Symbol is defined is the potential for inconsistent behavior between browsers when in use with libraries that support the fallback (Ramda being a fine example)."}}
{"actor":{"display_login":"leebyron"}}