Skip to content Skip to sidebar Skip to footer

Different Typeof 'this' When Calling/applying A Strict Function Vs. A Non-strict Function

It looks like when I'm using func.call(12) on some non-strict function func, it will use this = new Number(12) instead of this = 12 (see the snippet below). I noticed because typeo

Solution 1:

Is this expected behaviour?

Yes, it's expected behaviour. In sloppy mode, this is always an object - casting primitives to their respective wrapper objects. And worse, null and undefined get replaced with the global object.

Is there any way around it?

Just always use strict mode.

Post a Comment for "Different Typeof 'this' When Calling/applying A Strict Function Vs. A Non-strict Function"