map-keys.js 408 B

123456789101112131415161718
  1. "use strict";
  2. var callable = require("./valid-callable")
  3. , forEach = require("./for-each")
  4. , call = Function.prototype.call;
  5. module.exports = function (obj, cb /*, thisArg*/) {
  6. var result = {}, thisArg = arguments[2];
  7. callable(cb);
  8. forEach(
  9. obj,
  10. function (value, key, targetObj, index) {
  11. result[call.call(cb, thisArg, key, value, this, index)] = value;
  12. },
  13. obj
  14. );
  15. return result;
  16. };