get.js 581 B

123456789101112131415
  1. "use strict";
  2. var isArguments = require("es5-ext/function/is-arguments")
  3. , isString = require("es5-ext/string/is-string")
  4. , ArrayIterator = require("./array")
  5. , StringIterator = require("./string")
  6. , iterable = require("./valid-iterable")
  7. , iteratorSymbol = require("es6-symbol").iterator;
  8. module.exports = function (obj) {
  9. if (typeof iterable(obj)[iteratorSymbol] === "function") return obj[iteratorSymbol]();
  10. if (isArguments(obj)) return new ArrayIterator(obj);
  11. if (isString(obj)) return new StringIterator(obj);
  12. return new ArrayIterator(obj);
  13. };