Skip to content

Commit 62c8669

Browse files
authored
Update article.md
1 parent ccc0e93 commit 62c8669

File tree

1 file changed

+4
-4
lines changed
  • 1-js/06-advanced-functions/09-call-apply-decorators

1 file changed

+4
-4
lines changed

1-js/06-advanced-functions/09-call-apply-decorators/article.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func.call(context, arg1, arg2, ...)
135135

136136
It runs `func` providing the first argument as `this`, and the next as the arguments.
137137

138-
To put it simple, these two calls do almost the same:
138+
To put it simply, these two calls do almost the same:
139139
```js
140140
func(1, 2, 3);
141141
func.call(obj, 1, 2, 3)
@@ -241,7 +241,7 @@ There are many solutions possible:
241241

242242
1. Implement a new (or use a third-party) map-like data structure that is more versatile and allows multi-keys.
243243
2. Use nested maps: `cache.set(min)` will be a `Map` that stores the pair `(max, result)`. So we can get `result` as `cache.get(min).get(max)`.
244-
3. Join two values into one. In our particular case we can just use a string `"min,max"` as the `Map` key. For flexibility, we can allow to provide a *hashing function* for the decorator, that knows how to make a one value from many.
244+
3. Join two values into one. In our particular case we can just use a string `"min,max"` as the `Map` key. For flexibility, we can allow to provide a *hashing function* for the decorator, that knows how to make one value from many.
245245

246246

247247
For many practical applications, the 3rd variant is good enough, so we'll stick to it.
@@ -319,7 +319,7 @@ let wrapper = function() {
319319

320320
That's called *call forwarding*. The `wrapper` passes everything it gets: the context `this` and arguments to `anotherFunction` and returns back its result.
321321

322-
When an external code calls such `wrapper`, it is undistinguishable from the call of the original function.
322+
When an external code calls such `wrapper`, it is indistinguishable from the call of the original function.
323323

324324
Now let's bake it all into the more powerful `cachingDecorator`:
325325

@@ -438,7 +438,7 @@ So, technically it takes `this` and joins `this[0]`, `this[1]` ...etc together.
438438

439439
*Decorator* is a wrapper around a function that alters its behavior. The main job is still carried out by the function.
440440

441-
It is generally safe to replace a function or a method with a decorated one, except for one little thing. If the original function had properties on it, like `func.calledCount` or whatever, then the decorated one will not provide them. Because that is a wrapper. So one need to be careful if one uses them. Some decorators provide their own properties.
441+
It is generally safe to replace a function or a method with a decorated one, except for one little thing. If the original function had properties on it, like `func.calledCount` or whatever, then the decorated one will not provide them. Because that is a wrapper. So one needs to be careful if one uses them. Some decorators provide their own properties.
442442

443443
Decorators can be seen as "features" or "aspects" that can be added to a function. We can add one or add many. And all this without changing its code!
444444

0 commit comments

Comments
 (0)