JSFiddle - React, Tailwind, and code Playground
HTML
Quick demo: Using <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/defineProperty"><code>Object.defineProperty</code></a>. See source code.<br><br>
<script>
// Define a constant..
if ('defineProperty' in Object) {
try {
Object.defineProperty(window, 'foo', {value: function(){return 'OK: Constant';} });
} catch (e) {
document.write('Failed to call Object.defineProperty. Error message: ' + (e.message || e));
}
} else {
document.write('FAIL: Object.defineProperty is not supported - No constant defined!');
}
window.onerror = function(e) {
document.write('OK? Error message: ' + e);
};
</script>
<script>
// Function declaration
function foo(){return 'FAIL: Overwritten by function declaration.'};
// Print result
document.write(foo());
</script>