js中函数的参数为对象时候怎么操作

JavaScript010

js中函数的参数为对象时候怎么操作,第1张

javascript函数中的参数对象arguments是个对象,而不是数组。但它可以类似数组那样通过数字下表访问其中的元素,而且它也有length属性标识它的元素的个数。通常我们把它转换成数组用array的slice函数,示例代码如下:function

fn()

{

var

arr

=

array.prototype.slice.call(arguments,0)

alert(arr.length)}

function combineConfig(config)

{

let defconfig = {

name : "我是默认name",

age : "我是默认age:12",

}

defconfig = {...defconfig,...config}

return defconfig

}

function combineConfig_Object(config)

{

let defconfig = {

name : "我是默认name Object",

age : "我是默认age:12 Object",

}

Object.assign(defconfig, config)

return defconfig

}

function combineConfig_jquery(config)

{

let defconfig = {

name : "我是默认name jquery",

age : "我是默认age:12 jquery",

}

$.extend(defconfig, config)

return defconfig

}

function combineConfig_for(config)

{

let defconfig = {

name : "我是默认name jquery",

age : "我是默认age:12 jquery",

}

for (let k in config)

{

defconfig[k] = config[k]

}

return defconfig

}