1) Why does clickLink refer to a window object? Simply put: clickLink is not an event handler; by adding the onclick attribute to elements, you use the onclick native method as the handler that calls the function. this function is declared in the main area, so it points to a window object. To be clear: the behavior looks like this:
<p onclick='function(){window.clickLink(this);}'>
Make the real event handler an anonymous function, rather than clicking the link. That's why it will point to a window: an anonymous function has also been declared in the global scope, so the clickLink caller is a window.
2) Why is it in clickLink2 to print to the console as the value of the href link?
Think of this phrase "Javascript allows you to manipulate the DOM, DOM tree, all events and behavior." Your init function controls onclick controls. the default onclick method is canceled and replaced by the clickLink2 method here nodeArr[i].onclick = clickLink2; .
Look at it like this: all of your elements have a prototype of the onclick method, which takes a parameter. In the first case, this parameter is a string that computes the call to the clickLink function. However, in the second case, instances that have a specific class have their own onclick method, which overrides the onclick prototype.
I hope this makes it a little easier for you. It's easy as soon as you understand the basic philosophy of events, handlers, methods, prototypes, etc ... and overcome the quirks of JS.
3) Is there a better way to pass this to an unobtrusive application? how can you be sure what this means?
Well, sort of the answer is that above, right? but one way or another: if you yourself define the method of the element or object, in general, this will indicate the object / element of the owner. If you rely on html and default behavior, JS will mainly take into account its own business, and this will point to a window.
I don't know if this is an option, but maybe you could try something like this:
<a onclick='clickLink'>
this should - in theory - do the same thing as your init function
Edit: A working alternative to the above:
<p onclick='clickLink.call(this)'>
The call defines the p element as the calling clickLink element, making this point the element that calls the function.