JSFiddle - React, Tailwind, and code Playground
HTML
<h1>Value of <code>typeof this</code> inside each context and environment applied to a number</h1>
<table>
<thead>
<tr>
<td></td>
<th>Function</th>
<th>Getter</th>
</tr>
</thead>
<tbody>
<tr>
<th>Strict</th>
<td id="strict-function"></td>
<td id="strict-getter"></td>
</tr>
<tr>
<th>Non-strict</th>
<td id="non-strict-function"></td>
<td id="non-strict-getter"></td>
</tr>
</tbody>
</table>
CSS
h1 {
font-weight: bold;
margin-bottom: 20px;
}
th {
font-weight: bold;
}
th, td {
padding: 5px;
}
JavaScript
function callMe() {
document.getElementById("non-strict-function").textContent = typeof this;
}
function callMeStrict() {
"use strict";
document.getElementById("strict-function").textContent = typeof this;
}
Object.defineProperty(Object.prototype, "getMe", {
get: function() {
document.getElementById("non-strict-getter").textContent = typeof this;
}
});
Object.defineProperty(Object.prototype, "getMeStrict", {
get: function() {
"use strict";
document.getElementById("strict-getter").textContent = typeof this;
}
});
callMe.call(0);
callMeStrict.call(0);
(0).getMe;
(0).getMeStrict;