to-array.js 569 B

123456789101112131415161718192021
  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) { return [key, value]; };
  7. module.exports = function (obj/*, cb, thisArg, compareFn*/) {
  8. var a = [], cb = arguments[1], thisArg = arguments[2];
  9. cb = isValue(cb) ? callable(cb) : defaultCb;
  10. forEach(
  11. obj,
  12. function (value, key, targetObj, index) {
  13. a.push(call.call(cb, thisArg, value, key, this, index));
  14. },
  15. obj, arguments[3]
  16. );
  17. return a;
  18. };