javascript - How to make following clone function accept more than one param? -
i'm building simple clone function:
function clone (value) { return json.parse(json.stringify(value)) } the problem need also:
json.parse(json.stringify({}, object)) and:
json.parse(json.stringify({}, value, object)) how modify clone fuction accept additional params without breaking it?
one of uses of .apply method on function call array of arguments. can use solve problem.
function clone(...args) { return json.parse(json.stringify.apply(null, args)) } if need support browsers not support spread operator, , can't use build tool whatever reason, can use arguments instead. note arguments deprecated
function clone() { return json.parse(json.stringify.apply(null, arguments)) }
Comments
Post a Comment