* Allow rest/spread on polyfilled or builtin iterables when `Symbol` unsupported Currently, when `Symbol` is not supported, we allow using rest/spread with: - arrays - strings - arguments With this PR, it will be also possible to use it with - maps - sets - binary arrays While in old browsers es6 builtins would still need to be polyfilled, it's way easier to polyfill them because `Symbol` cannot be reliably polyfilled. I didn't use `instanceof` becase: - it doesn't work with polyfills not attatched to the global scope - when using Babel to load polyfills, it would force the inclusion of `Map` and `Set` polyfills even if they are not used Downside: the current approach of relying on `toString || construcor.name` doesn't work with subclasses. * Don't use Array.from for array-like objects
13 lines
396 B
JavaScript
13 lines
396 B
JavaScript
var arrayWithHoles = require("./arrayWithHoles");
|
|
|
|
var iterableToArray = require("./iterableToArray");
|
|
|
|
var unsupportedIterableToArray = require("./unsupportedIterableToArray");
|
|
|
|
var nonIterableRest = require("./nonIterableRest");
|
|
|
|
function _toArray(arr) {
|
|
return arrayWithHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableRest();
|
|
}
|
|
|
|
module.exports = _toArray; |