<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>对象解构3:部分解构</title>
</head>
<body>
<script>
let person = {
name:'fbb',
age:38,
job:{
title:'woman of gpl'
}
};
//设计多个属性的解构赋值是输出无关的顺序化操作
//如果一个解构表达式涉及多个赋值,开始的赋值成功而后面的赋值出错,则整个解构赋值只会完成一部分
let pname,page,pjob;
try{
({
name: pname,
foo:{bar:pbar},
age:page,
job: {
title: pjob
}
} = person);
}
catch (e){
console.log(e);
} //Cannot read properties of undefined (reading 'bar')
console.log(pname); //fbb
console.log(page); //undefined
console.log(pjob); //undefined
</script>
</body>
</html>
标签:console,log,pjob,对象,undefined,解构,部分,赋值 From: https://www.cnblogs.com/polin/p/17134569.html