Search code examples
javascriptinternet-explorerinternet-explorer-9

IE9 cast context 'this' to Object


I've found out strange behavior in IE9. Lets say we have a function that return context:

function toContext() { return this; }

In IE9, if I call it with some primitive context, the context is casted to Object

toContext.call(3);  // => [object Number]
toContext.call(""); // => [object String]

In IE10 and later, it returns passed primitive, but IE9 gives this strange results, which spoils my coding pattern.

I emulate IE9 in IE11, maybe this is problem with a emulation. I searched for this behavior of old IE, but found nothing usefull. Can someone confirm that this behavior affects native IE9 or maybe someone know more about this topic?


Solution

  • IE9 does not support strict mode, which you seem to be using but is necessary to get primitive this values.