<!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>
const person = {
name: "jack",
age: 21,
language: ['java', 'js', 'css']
}
console.log(Object.keys(person));
console.log(Object.values(person));
console.log(Object.entries(person));
const target = {a:1}
const source1 = {b:"2"}
const source2 = {c:3}
Object.assign(target, source1, source2)
console.log(target)
const age = 23
const name = "zhangsan"
const person1 = {age:age, name:name}
console.log(person1)
const person2 = {age, name}
console.log(person2)
let person3 = {
name:"jack",
eat:function(food) {
console.log(this.name + "在吃" + food)
},
eat2: food => console.log(this.name + "在吃" + food),
eat3: food => console.log(person3.name + "在吃" + food)
}
person3.eat("apple")
person3.eat2("apple")
person3.eat3("apple")
let person4 = {
name: "Amy",
age: 15
}
let someone = { ...person4 }
console.log(someone)
let age1 = { age: 15 }
let name1 = { name: "Amy" }
let person5 = { ...age1, ...name1 }
console.log(person5)
</script>
</body>
</html>
|