]> gerrit.simantics Code Review - simantics/district.git/blob - copy.js
e1467f7671946ca2801d8ef6cbf138cd9db54877
[simantics/district.git] / copy.js
1 'use strict';
2
3 var mixin         = require('../../object/mixin')
4   , validFunction = require('../valid-function')
5
6   , re = /^\s*function\s*([\0-'\)-\uffff]+)*\s*\(([\0-\(\*-\uffff]*)\)\s*\{/;
7
8 module.exports = function () {
9         var match = String(validFunction(this)).match(re), fn;
10
11         fn = new Function('fn', 'return function ' + match[1].trim() + '(' +
12                 match[2] + ') { return fn.apply(this, arguments); };')(this);
13         try { mixin(fn, this); } catch (ignore) {}
14         return fn;
15 };