shim.js 680 B

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