<!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>
var name = "Pning";
var professional = "JavaWeb开发";
var info = {
name,
professional,
go(){
console.log(info);
}
};
//1、通过.获取
console.log("通过.获取");
console.log(info.name);
console.log(info.professional);
info.go();
//通过[]获取
console.log("通过[]获取");
console.log(info["name"]);
console.log(info["professional"]);
info["go"]();
//es6的结构对象
console.log("通过结构对象获取");
var {name,professional,go} = info;//可以自己挑属性
var {name,go} = info;
console.log({name,professional,go});
console.log({name,go});
</script>
</body>
</html>
6_获取对象的属性和方法(含结构对象取法)
最新推荐文章于 2023-09-10 16:41:07 发布