<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="./jquery-1.12.4.js"></script>
<script>
let objStudent1 = {
name: 'zhangsan',
age: 18,
study: {
lesson: "大数据",
score: "80"
}
}
let objStudent2 = {
name: 'lisi',
car: 'bmw',
watch: 'lls',
study: {
lesson: "前端"
}
}
let newobj = $.extend(false, objStudent1, objStudent2);
console.log('合并的新对象', newobj);
console.log('学生对象1', objStudent1);
console.log('学生对象2', objStudent2);
</script>
</body>
</html>
let newobj = $.extend(false, objStudent1, objStudent2);的运行结果
let newobj = $.extend(true, objStudent1, objStudent2);的运行结果
总结:
把两个对象合并成到一个新的对象,默认为false
不管是true还是false,1中没有的内容,2中有,就会添加到合成的里面去
如果是false,同样的“名字”,1中原来的内容会被2中的内容覆盖
如果是true,对于1中有,2中没有的内容,会保留下来