首页 > 其他 > 详细

合并对象

时间:2019-12-15 21:58:28      阅读:92      评论:0      收藏:0      [点我收藏+]

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"
})

合并对象

原文:https://www.cnblogs.com/yuyedaocao/p/12045920.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!