copy.js 541 B

12345678910111213141516171819202122
  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 { mixin(fn, this); }
  17. catch (ignore) {}
  18. return fn;
  19. };