1
0

copy.js 475 B

123456789101112131415
  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. fn = new Function('fn', 'return function ' + match[1].trim() + '(' +
  8. match[2] + ') { return fn.apply(this, arguments); };')(this);
  9. try { mixin(fn, this); } catch (ignore) {}
  10. return fn;
  11. };