Skip to content

Commit cdfc0c3

Browse files
committed
explainer § Why: Stub other justifications
See #8.
1 parent 04e7527 commit cdfc0c3

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,30 @@ is equivalent to `a->(createFn())`.
7272
There are **no other special rules**.
7373

7474
## Why a bind-`this` operator
75+
76+
### `call` and `bind` are very common and should be easier
7577
[`Function.prototype.bind`][call] and [`Function.prototype.call`][bind]
76-
are very common in **object-oriented JavaScript** code.
77-
They are useful methods that allows us to apply functions to any object,
78+
are very common in **object-oriented JavaScript** code;
79+
they could even be considered core parts of its design.
80+
81+
[TODO]
82+
83+
[bind]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
84+
[call]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
85+
86+
### Tree-shakable methods should be easier
87+
They allow developers to apply functions to any object,
7888
binding their first arguments to the `this` bindings within those functions,
7989
no matter the current object environment.
8090
`bind` and `call` allow us to **extend** an **object** with a function
8191
as if that function were **its own method**.
8292
They serve as an important link between
8393
the **object-oriented** and **functional** styles in JavaScript.
8494

85-
[bind]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
86-
[call]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
95+
[TODO]
8796

88-
Why then would we need an operator that does the same thing?
89-
Because `bind` and `call` are vulnerable to **global mutation**.
97+
### Protection against global mutation should be easier
98+
`Function.prototype.bind` and `call` are vulnerable to **global mutation**.
9099

91100
For example, when we run our code in an untrusted environment,
92101
an adversary may mutate global prototype objects

0 commit comments

Comments
 (0)