JSFiddle - React, Tailwind, and code Playground
HTML
<section>
<h1>Non-strict</h1>
<p>Typeof <code>this</code> inside a function when called on a number: <code id="typeof-1"></code></p>
<p>Typeof <code>this</code> inside an <code>Object.prototype</code> getter when used on a number: <code id="typeof-2"></code></p>
</section>
<section>
<h1>Strict</h1>
<p>Typeof <code>this</code> inside a function when called on a number: <code id="typeof-strict-1"></code></p>
<p>Typeof <code>this</code> inside an <code>Object.prototype</code> getter when used on a number: <code id="typeof-strict-2"></code></p>
</section>
CSS
section {
margin: 30px 10px;
}
h1 {
font-weight: bold;
line-height: 1.5;
}
JavaScript
function callMe() {
document.getElementById("typeof-1").textContent = typeof this;
}
Object.defineProperty(Object.prototype, "getMe", {
get: function() {
document.getElementById("typeof-2").textContent = typeof this;
}
});
callMe.call(0);
(0).getMe;
///////////////
function callMeStrict() {
"use strict";
document.getElementById("typeof-strict-1").textContent = typeof this;
}
Object.defineProperty(Object.prototype, "getMeStrict", {
get: function() {
"use strict";
document.getElementById("typeof-strict-2").textContent = typeof this;
}
});
callMeStrict.call(0);
(0).getMeStrict;