0
0

to-array.js 510 B

123456789101112131415161718
  1. 'use strict';
  2. var callable = require('./valid-callable')
  3. , forEach = require('./for-each')
  4. , call = Function.prototype.call
  5. , defaultCb = function (value, key) { return [key, value]; };
  6. module.exports = function (obj/*, cb, thisArg, compareFn*/) {
  7. var a = [], cb = arguments[1], thisArg = arguments[2];
  8. cb = (cb == null) ? defaultCb : callable(cb);
  9. forEach(obj, function (value, key, obj, index) {
  10. a.push(call.call(cb, thisArg, value, key, this, index));
  11. }, obj, arguments[3]);
  12. return a;
  13. };