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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -