copy.js 543 B

1234567891011121314151617181920212223
  1. "use strict";
  2. var mixin = require("../../object/mixin")
  3. , validFunction = require("../valid-function")
  4. , re = /^\s*function\s*([\0-')-\uffff]+)*\s*\(([\0-(*-\uffff]*)\)\s*\{/;
  5. module.exports = function () {
  6. var match = String(validFunction(this)).match(re), fn;
  7. // eslint-disable-next-line no-new-func
  8. fn = new Function(
  9. "fn",
  10. "return function " +
  11. match[1].trim() +
  12. "(" +
  13. match[2] +
  14. ") { return fn.apply(this, arguments); };"
  15. )(this);
  16. try {
  17. mixin(fn, this);
  18. } catch (ignore) {}
  19. return fn;
  20. };