After running the test with PhantomJS, it is possible for the test to fail due to certain console.log
issues. To address this, I have found that adding the following line at the top inside the Immediately Invoked Function Expression (IFFE) helps resolve the problem:
var console = window.console;
Initially, this seems peculiar. Isn't PhatomJS based on Webkit, where both console
and console.log
are already defined?
Furthermore, if window.console
is already defined and we assign it using var console = window.console;
, wouldn't the browser automatically use window.console
when encountering console
in the global environment?
I believe that if the console.log(...)
statements were replaced by window.console.log(...)
, there would be no need for var console = window.console;
.
So why is var console = window.console;
necessary, and what issue does it help resolve?