It seems that in PhantomJS, console
is a bit special in that it is not an instance of Function
(contrary to Chrome or Firefox). Hence extending Function.prototype
has no action on it.
console.log(typeof console.log === "function");
// true
console.log(console.log instanceof Function);
// false
(probably the console.log
comes from a different JavaScript context, and the issue here is the same as with myArray instanceof Array
evaluating to false
when myArray
comes from an iframe).
To fix the issue, apart from including a polyfill for Function.prototype.bind
, you could assign bind
to console
methods manually, like this:
if (!console.log.bind) {
// PhantomJS quirk
console.log.constructor.prototype.bind = Function.prototype.bind;
}
After this, all console methods will have .bind()
:
console.log(console.log.bind); // function bind(obj) { ... }
console.log(console.info.bind); // function bind(obj) { ... }
console.log(console.debug.bind); // function bind(obj) { ... }
console.log(console.warn.bind); // function bind(obj) { ... }
console.log(console.error.bind); // function bind(obj) { ... }