en.javascript.info
en.javascript.info copied to clipboard
Page: Decorators and forwarding, call/apply
Decorators and forwarding, call/apply https://javascript.info/call-apply-decorators
Problem
I've discussed the confusion involving this page of the tutorial with Joseph on the discord server. The call
and apply
function prototype methods should be introduced on their own before touching on the topic of decorators or caches. The comments on this page are also unanimous in describing the content as confusing.
Possible Solutions
Page Title Joseph proposed a title change to something like "Wrapper functions and call, apply methods". I agree that the title is misleading or poorly worded. Perhaps it should follow the pattern of the other pages' titles in the Advanced working with functions section:
The apply and call methods
Page Content I believe the content should be rearranged so that discussion of how the apply and call methods work comes first. The topics of decorators and transparent caching can follow afterwards. There are many uses for these methods, so it's a bit confusing to introduce them as a means to write decorators.
Links https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
I'll try to get Joseph to chime in if possible.
The title does seem a bit out of place
The content is arranged like this, because .call/apply
in practice is used mainly for decorators and alike.
So I introduce the problem first, and then describe .call/apply
as the solution. So it becomes clear why they are needed.
Anything wrong with it?
Hi there,
I am the Joseph referenced :-)
Please let me preface that I am obviously not a subject matter expert. However, having followed the tutorial diligently so far, I can say this was the most confusing chapter - and not because of the principals introduced.
I would have found it much easier to follow along if bind, then call and apply were explained. And then introduce decorators et al in a separate chapter, afterwards.
I ended up having to ditch the chapter and found this excellent YT video that explained the concepts in the order suggested above.
The introduction to decorators themselves added to the confusion, starting off with the "Transparent caching" sub-header. I really feel that a "gentler" introduction is warranted for this advanced subject. Giving some background before diving in. I also got extremely confused when Googling as I kept coming across the new @ decorator syntax that is not in the language yet.
Perhaps you might suggest that this is "one persons issue", I would disagree since I had followed most of the previous chapters without this level of confusion and upon looking through the comments at the page bottom, there is a similar consensus.
I agree with Joseph. I don't think the problem should be introduced first in this case. call/apply
are not needed to make decorators. They are simply one way to do so. These concepts are already strange in most general purpose programming languages, so I think it would be better off explaining them first.
My opinion aside, I don't believe there is any reason to debate whether or not the order of information is sub-optimal. The multitude of comments from confused learners is all the proof we need on this matter. We should discuss how to re-arrange the content and then do so.
We might put the .call/apply
introduction block above the transparent caching.
Although, it makes no sense to introduce them without a practical example at all. So there must be such example in this article.
Could you suggest a PR for a viable reorganization?
Although, it makes no sense to introduce them without a practical example at all.
I'm not sure I agree with this statement. A practical example is extremely useful, sure. I think the real issue here is that neither apply
nor call
are actually being used in this example when it is first shown. The example is written one way, then the tutorial retroactively changes the example to use call
, then apply
. This style of teaching is sub-optimal and disliked by many students, myself included. It would be better to show the example using call
or apply
first, then show the harder version that uses neither later.
To come up with a good reorganization, someone might need to read through the comments to see what confused students the most. I can take some time to do it later this week.
My personal experience here. I'm a veteran in old tech, I got the wrappers concept right here and I loved them: It was not hard nor confusing, but the way I learn I prefer
Use titles as hooks
-
as suggested, put "wrappers" in the title so it gets to the main index: the wrapper abstract is important.
-
I don't like "Transparent caching" at the top. Guess the problem is not the order but the importance, I would make it clear it is THE example
Example/use case/real-life drama: "Transparent caching"
It feels out of place
Naming things is important Edit: wow, I just read the comments and it refreshed things I struggled with and I completely forgot.