Skip to content

Commit e80a8d6

Browse files
authored
docs: improve description for no-dynamic-delete (#9195)
1 parent 9f92b30 commit e80a8d6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/eslint-plugin/docs/rules/no-dynamic-delete.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ import TabItem from '@theme/TabItem';
1111
1212
Deleting dynamically computed keys can be dangerous and in some cases not well optimized.
1313
Using the `delete` operator on keys that aren't runtime constants could be a sign that you're using the wrong data structures.
14-
Using `Object`s with added and removed keys can cause occasional edge case bugs, such as if a key is named `"hasOwnProperty"`.
14+
Consider using a `Map` or `Set` if you’re using an object as a key-value collection.
1515

16-
> Consider using a `Map` or `Set` if you’re storing collections of objects.
16+
Dynamically adding and removing keys from objects can cause occasional edge case bugs. For example, some objects use "hidden properties" (such as `__data`) for private storage, and deleting them can break the object's internal state. Furthermore, [`delete`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete) cannot remove inherited properties or non-configurable properties. This makes it interact badly with anything more complicated than a plain object:
17+
18+
- The [`length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length) of an array is non-configurable, and deleting it is a runtime error.
19+
- You can't remove properties on the prototype of an object, such as deleting methods from class instances.
20+
- Sometimes, `delete` only removes the own property, leaving the inherited property intact. For example, deleting the [`name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) property of a function only removes the own property, but there's also a `Function.prototype.name` property that remains.
1721

1822
## Examples
1923

0 commit comments

Comments
 (0)