Skip to content

Commit 3551cdd

Browse files
committed
fix: Do not rely on problematic regex
Addresses #201
1 parent 7855319 commit 3551cdd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

function/#/copy.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
"use strict";
22

33
var mixin = require("../../object/mixin")
4-
, validFunction = require("../valid-function")
5-
, re = /^\s*function\s*([\0-')-\uffff]+)*\s*\(([\0-(*-\uffff]*)\)\s*\{/;
4+
, validFunction = require("../valid-function");
65

76
module.exports = function () {
8-
var match = String(validFunction(this)).match(re), fn;
7+
validFunction(this);
98

9+
var args = [];
10+
for (var i = 0; i < this.length; ++i) args.push("arg" + (i + 1));
1011
// eslint-disable-next-line no-new-func
11-
fn = new Function(
12+
var fn = new Function(
1213
"fn",
1314
"return function " +
14-
match[1].trim() +
15+
(this.name || "") +
1516
"(" +
16-
match[2] +
17+
args.join(", ") +
1718
") { return fn.apply(this, arguments); };"
1819
)(this);
1920
try { mixin(fn, this); }

0 commit comments

Comments
 (0)