So I'm getting the error 'Invalid Calling Object' in IE11 when trying to execute the following:
window.toString.call({});
When I expect to see => "[object Object]"
This form seems to works though:
({}).toString();
Both forms appear to work fine in chrome, am I missing something?
You seem to be neglecting the fact
window.toString === Object.prototype.toString; // false
The Window's toString
is implementation-specific and there is nothing in the specification saying methods on DOM Host Objects have to work with call
/on other objects/etc
If you want to capture this toString
but can't assume prototype, try
var toString = ({}).toString;
toString.call({}); // "[object Object]"
You could also consider skipping call
each time by wrapping it or using bind
var toString = function (x) { return ({}).toString.call(x); };
toString(10); // "[object Number]"
// or
var toString = ({}).toString.call.bind(({}).toString);
toString(true); // "[object Boolean]"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With