The Ninja starts the 3rd chapter assuming readers will be surprised by that he declares as THE most important concept in JS functions, and not objects.
Hm. But I am not surprised. Should I be?
Yes, the word is allover:
Objects. Object-oriented-programing. Everything is an object. And all that (almost philosophical sentences are to be found when getting into programming). But
functions are allover as well.
So why is that such a big point? Ninja says:
“JS is a functional language. Functions are fundamental to JS. Functions in JS are first class ojects.”
Well ok then. Fine. Functions it is. Off we go, first things to learn:
- Be created via literal
- Be assigned to variables
- Be passed as arguments to functions
- Be returned as values from functions
- Posses properties that can be dynamically created and assigned
- And as the extra topping of whipped object cream:
“Functions are objects that can be invoked.”
Ok. So that’s that.
I stumble over vague insecurities in my JS vocabulary all the time. For this reading and learning project, I want to take advantage of the luxurious situation I have, that there are a bunch of lovely, experienced and supportive colleagues around me, whom I can ask the most basic questions. Their patience is infinite, I think.
While continue reading with the Ninja today, it comes to words as events, handlers and listeners and I realize, I think I do know, but am not absolutely sure about how these are defined exactely in JS.
handlers are basically functions, that treat some sort of event. I read it up but can’t find a 100% answer. Asking Timo, one of my backend colleagues, I get this beautiful reply (I mentioned philosophy in programming before):
“Hmm, I think of a handler as a thing that takes another thing and then does something. What a thing or something is, depends on the language and other things.”
He clarified further of course, and Jezen joined in as well, so finally now I know, what you knew: Yes, in JS, handlers are functions.
The other word with a vague concept is
events. I know what an event can be and do, but am unsure about what I do not know (well, is anyone ever?). Here is what the ninja lists as most important event categories in JS (and in brackets I add an example, correct me if I got one wrong):
- Browser events (e.g. window.open, “open” = the event)
- Network events (e.g. navigator.online, “online” = the event)
- User events (e.g. button.onclick. “onclick” = the event)
- Timer events (e.g. today.getHours = “getHours” is the event)
So, an event is “the thing supposed to happen”. It seems to be as simple as that.
The next one is
listener. The word is dropping frequently and I even use it, but again am not on absolute safe ground here. How I understand it after reading up: A
listener is also a handler, one for the case that something isn’t always executed but only triggered, when something actively happened, typically a user triggering some event.
If only the fantastic stackoverflow would be a living person. I would travel far to meet it/him/her and bring flowers. This hidden crowd’s knowledge sharing, where seemingly no question has no answer. Anyway.
Still I am curious whether there is not a major misconception in what I wrote but my fellow colleagues will sure tell me.
Next time on the menu: