Question:JS Cert,Exc.:Hazards of using imperative code

Dear campers, I have a small question. I understood 99,9% of the challenge: Understand the Hazards of Using Imperative Code
There is just this little secret left:

Window.prototype.tabOpen = function(tab) {
this.tabs.push(‘new tab’);
return this;

Why are we inserting a parameter ‘tab’ → function(tab) ?
The function never receives anything!
I cut it out, and the code still works.
And why would the function even work, when it won’t receive anything, although it must have ‘tab’? Iam just a bit confused, it does not make sense to meee! Please help me.

ps Have to say it was a really good challenge, I learned tons of stuff!

1 Like

That is a good question. It’s actually quite different from when you write code from scratch.

Main Concept

The reason is the EventListener WebAPI,. Basically the browsers have Listener functions, which are executed in response some client event (a click, drag, keyup, etc etc!).

In summary, these listener functions are executed by the browser at some events, and always pass the resultant event object to it.

When a tab is opened, the browser will execute: Window.prototype.taOpen(e) or more generally element.listener(e). e is a placeholder for a better name, in your case you call it tab.

Thank you very much santimir :- )

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.