91
rated 0 times
[
92]
[
1]
/ answers: 1 / hits: 133651
/ 15 Years ago, wed, december 2, 2009, 12:00:00
What is a fastest way to clone a function in JavaScript (with or without its properties)?
Two options coming to mind are eval(func.toString())
and function() { return func.apply(..) }
. But I am worried about performance of eval and wrapping will make stack worse and will probably degrade performance if applied a lot or applied to already wrapped.
new Function(args, body)
looks nice, but how exactly can I reliable split existing function to args and body without a JS parser in JS?
Update:
What I mean is being able to do
var funcB = funcA.clone(); // where clone() is my extension
funcB.newField = {...}; // without affecting funcA
More From » function