Why are certain function calls termed “illegal invocations” in JavaScript?

It’s because you’ve lost the “context” of the function. When you call: document.querySelectorAll() the context of the function is document, and will be accessible as this by the implementation of that method. When you just call q there’s no longer a context – it’s the “global” window object instead. The implementation of querySelectorAll tries to … Read more

The invocation context (this) of the forEach function call

MDN states: array.forEach(callback[, thisArg]) If a thisArg parameter is provided to forEach, it will be used as the this value for each callback invocation as if callback.call(thisArg, element, index, array) was called. If thisArg is undefined or null, the this value within the function depends on whether the function is in strict mode or not … Read more

Uncaught TypeError: Illegal invocation in JavaScript

The console’s log function expects this to refer to the console (internally). Consider this code which replicates your problem: var x = {}; x.func = function(){ if(this !== x){ throw new TypeError(‘Illegal invocation’); } console.log(‘Hi!’); }; // Works! x.func(); var y = x.func; // Throws error y(); Here is a (silly) example that will work, … Read more

Which overload will get selected for null in Java?

The most specific method will be called – in this case showInputDialog(Component parent, Object message) This generally comes under the “Determine Method Signature” step of overload resolution in the spec (15.12.2), and in particular “Choosing the Most Specific Method”. Without getting into the details (which you can read just as well in the spec as … Read more