合并对象
1、Object.assign
function custion (options) { this.default = { width : 100 , height : 100 , color : "red" } this.settings = Object.assign(this.default , options) console.log(this.settings.width) //显示 {width: 200, height: 100, color: "red", background: "red"} } custion({ width : 200 , background: "red" })
2、Jquery中 $.extend:
function custion (options) { this.default = { width : 100 , height : 100 , color : "red" } this.settings = $.extend(this.default , options)
console.log(this.settings.width)
//显示 {width: 200, height: 100, color: "red", background: "red"} }
custion({
width : 200 ,
background: "red"
})