Skip to content

Commit 77dabb2

Browse files
committed
Update subclass-restriction-motivation.md
1 parent 1fac1ca commit 77dabb2

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

subclass-restriction-motivation.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
Basically, because it breaks encapsulation.
44

5-
In ES 2015 + web reality, there are three ways to interact with the internals of a regexp:
5+
In ES 2015 + web reality, there are two ways to set the semantics of a regexp:
66

7-
1. Perform a match using the `RegExp.prototype.exec()` method. (Recall that all other methods that needs to execute a regexp are written in terms of `RegExp.prototype.exec()`);
8-
2. modify the regexp with the deprecated `RegExp.prototype.compile()` method;
9-
3. retrieve information on the result of the last successful match with the deprecated `RegExp.$1`, etc. static properties.
7+
1. using the constructor (at construction time);
8+
2. using the deprecated `RegExp.prototype.compile()` method.
9+
10+
Similarly, there are two ways to get information about a successful match:
11+
12+
1. reading the returned value of the `RegExp.prototype.exec()` method. (Recall that all other methods that needs to execute a regexp are written in terms of `RegExp.prototype.exec()`);
13+
2. reading the deprecated `RegExp.$1`, etc. static properties.
1014

11-
A subclass of `RegExp` may want to redefine `RegExp.prototype.exec()`, without caring of the legacy features, leaving them as potentially broken.
15+
A subclass of `RegExp` may want to redefine the constructor and the `exec()` method, without caring about the legacy features, leaving them as potentially broken.
1216

1317
Below are concrete illustrations of what could be wrong.
1418

0 commit comments

Comments
 (0)