shim.js 648 B

123456789101112131415161718192021
  1. "use strict";
  2. var isPlainArray = require("../../is-plain-array")
  3. , callable = require("../../../object/valid-callable")
  4. , isArray = Array.isArray, map = Array.prototype.map
  5. , forEach = Array.prototype.forEach, call = Function.prototype.call;
  6. module.exports = function (callbackFn/*, thisArg*/) {
  7. var result, thisArg;
  8. if (!this || !isArray(this) || isPlainArray(this)) {
  9. return map.apply(this, arguments);
  10. }
  11. callable(callbackFn);
  12. thisArg = arguments[1];
  13. result = new this.constructor(this.length);
  14. forEach.call(this, function (val, i, self) {
  15. result[i] = call.call(callbackFn, thisArg, val, i, self);
  16. });
  17. return result;
  18. };