I am looking to throw a TypeError whenever a particular function in non-strict mode is called with null / undefined. There is a partial workaround by forcing the function to locally execute in strict mode, but it's an incomplete solution.
var t = function(s) { console.log(this) };
t.call(null), t.call(undefined); // window, window
(function() {
"use strict";
t = function(s) { console.log(this) }
t.call(null), t.call(undefined); // null, undefined
})();
I also can't throw if this is window, as the function may be legitimately called with this as the global object. Is there a complete workaround not involving use strict?