JSFiddle - React, Tailwind, and code Playground
JavaScript
(function() {
var actualValue;
Object.defineProperty(window, 'unreadable', {
set: function(value) {
// Allow all setters for example
actualValue = value;
},
get: function() {
if (/somepattern/.test(arguments.callee.caller)) {
// Restore, by deleting the property, then assigning value
delete window.unreadable;
window.unreadable = actualValue;
throw 'Prevented execution!';
}
return actualValue;
},
configurable: true // Allow re-definition of property descriptor
});
})();
function notok() {var somepattern = window.unreadable; return 'ok'}
function nowok() {var somepattern = window.unreadable; return 'ok'}
function ok() {return unreadable;}
//]]></script><script>//<![CDATA[
var unreadable = 'Readable';
console.log(notok()); // Fail
//]]></script><script>//<![CDATA[
console.log(nowok()); // Same code,
//]]></script><script>//<![CDATA[
console.log(ok()); // OK
//]]></script><script>//<![CDATA[