Skip to content

Commit

Permalink
Update Object.md
Browse files Browse the repository at this point in the history
  • Loading branch information
yihan12 authored Dec 14, 2023
1 parent 5ddbb7a commit 15b9af9
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions javascript/Data Types/Object.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,26 @@ console.log(obj1.propfirst);

例2:
```javascript
let obj1 = {
propfirst : "Name"
}
// Output : Name
console.log(obj1.propfirst)
let obj2 = Object.create(obj1);

// Output : Name
console.log(obj2.propfirst);

// Output : true.
console.log(delete obj2.propfirst);

// Output : Name
console.log(obj2.propfirst);

// Output : true
console.log(delete obj1.propfirst);

// Output : undefined
console.log(obj2.propfirst);
```
对比例1和例2不难发现,delete能删除本身的属性,但是不能删除继承的属性。删除调obj1的propfirst属性后,会影响到obj2的继承属性。

0 comments on commit 15b9af9

Please sign in to comment.