to-array.js 573 B

123456789101112131415161718192021222324
  1. "use strict";
  2. var callable = require("./valid-callable")
  3. , isValue = require("./is-value")
  4. , forEach = require("./for-each")
  5. , call = Function.prototype.call
  6. , defaultCb = function (value, key) {
  7. return [key, value];
  8. };
  9. module.exports = function (obj /*, cb, thisArg, compareFn*/) {
  10. var a = [], cb = arguments[1], thisArg = arguments[2];
  11. cb = isValue(cb) ? callable(cb) : defaultCb;
  12. forEach(
  13. obj,
  14. function (value, key, targetObj, index) {
  15. a.push(call.call(cb, thisArg, value, key, this, index));
  16. },
  17. obj,
  18. arguments[3]
  19. );
  20. return a;
  21. };