{"action":"created","issue":{"url":"https://api.github.com/repos/sebmarkbage/ecmascript-rest-spread/issues/2","labels_url":"https://api.github.com/repos/sebmarkbage/ecmascript-rest-spread/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/sebmarkbage/ecmascript-rest-spread/issues/2/comments","events_url":"https://api.github.com/repos/sebmarkbage/ecmascript-rest-spread/issues/2/events","html_url":"https://github.com/sebmarkbage/ecmascript-rest-spread/issues/2","id":67266499,"number":2,"title":"Use object iterator, if present","user":{"login":"getify","id":150330,"avatar_url":"https://avatars.githubusercontent.com/u/150330?v=3","gravatar_id":"","url":"https://api.github.com/users/getify","html_url":"https://github.com/getify","followers_url":"https://api.github.com/users/getify/followers","following_url":"https://api.github.com/users/getify/following{/other_user}","gists_url":"https://api.github.com/users/getify/gists{/gist_id}","starred_url":"https://api.github.com/users/getify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getify/subscriptions","organizations_url":"https://api.github.com/users/getify/orgs","repos_url":"https://api.github.com/users/getify/repos","events_url":"https://api.github.com/users/getify/events{/privacy}","received_events_url":"https://api.github.com/users/getify/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-09T02:36:53Z","updated_at":"2015-04-09T12:21:28Z","closed_at":null,"body":"If you use `...o` in a spread context and the `o` in question has defined a `Symbol.iterator`, it would make more sense to use that than to just iterate own properties, in the same way that arrays work.\r\n\r\nSo, it should first check for the `Symbol.iterator`, and use it if present, otherwise fall back to the own-keys iteration."},"comment":{"url":"https://api.github.com/repos/sebmarkbage/ecmascript-rest-spread/issues/comments/91213050","html_url":"https://github.com/sebmarkbage/ecmascript-rest-spread/issues/2#issuecomment-91213050","issue_url":"https://api.github.com/repos/sebmarkbage/ecmascript-rest-spread/issues/2","id":91213050,"user":{"login":"getify","id":150330,"avatar_url":"https://avatars.githubusercontent.com/u/150330?v=3","gravatar_id":"","url":"https://api.github.com/users/getify","html_url":"https://github.com/getify","followers_url":"https://api.github.com/users/getify/followers","following_url":"https://api.github.com/users/getify/following{/other_user}","gists_url":"https://api.github.com/users/getify/gists{/gist_id}","starred_url":"https://api.github.com/users/getify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getify/subscriptions","organizations_url":"https://api.github.com/users/getify/orgs","repos_url":"https://api.github.com/users/getify/repos","events_url":"https://api.github.com/users/getify/events{/privacy}","received_events_url":"https://api.github.com/users/getify/received_events","type":"User","site_admin":false},"created_at":"2015-04-09T12:21:28Z","updated_at":"2015-04-09T12:21:28Z","body":"> What do you mean, use it if present.\r\n\r\nSomething like:\r\n\r\n```js\r\nvar o = {\r\n   [Symbol.iterator]: function*() {\r\n      yield \"a\";\r\n      yield \"c\";\r\n   },\r\n   a: 1,\r\n   b: 2,\r\n   c: 3\r\n};\r\n\r\nvar keysToCopy = (function(){\r\n   if (Symbol.iterator in o) return [...o];\r\n   else return Object.getOwnPropertyNames(o);\r\n})();\r\n\r\nkeysToCopy; // [\"a\",\"c\"]\r\n```\r\n\r\n> What would the interator return, string keys?\r\n\r\nInitially, that was my thought, yes, as above.\r\n\r\nBut it would be even more powerful, and make more sense in line with arrays and other iterables if it could actually act like the `entries()` iterator on collections:\r\n\r\n```js\r\nvar o = {\r\n   [Symbol.iterator]: function*() {\r\n      yield [\"a\", 10];\r\n      yield [\"c\", this.c];\r\n   },\r\n   a: 1,\r\n   b: 2,\r\n   c: 3\r\n};\r\n\r\nvar propsToCopy = (function(){\r\n   if (Symbol.iterator in o) return [...o];\r\n   else if (o.entries) return o.entries();\r\n   else {\r\n      return Object.getOwnPropertyNames(o).map(function(k){\r\n         return [k,o[k]];\r\n      });\r\n   }\r\n})();\r\n\r\npropsToCopy; // [ [\"a\",10], [\"c\",3] ]\r\n```\r\n\r\nIn other words, with arrays an other iterables, I currently have the freedom to declare an iterator on the value that can completely customize what the output of the `...` spread is, so it'd make most sense if I could do the same with any object or collection.\r\n\r\nThe default behavior of `...o` would still be to get the enumerable own properties (or whatever), but it should be possible to override that if I want to."}}