JSFiddle - React, Tailwind, and code Playground
by Jeremy Banks
HTML
<p>
Chrome users must <q>Enable Experimental JavaScript</q> in <code>chrome://flags/</code> to run this example.
</p>
JavaScript
function scope(parent) {
var parentScope = (parent != undefined) ? parent : null;
var scopeObj = Object.create(parentScope);
scopeObj.currentScope = scopeObj;
scopeObj.parentScope = parentScope;
scopeObj.scope = function(parent) {
if (parent == null) {
parent = scopeObj;
}
return scope(parent);
}
return scopeObj;
}
with(scope()) {
currentScope.x = 10;
console.log(x); // 10
console.log(currentScope.x); // 10
console.log(parentScope); // null
with(scope()) {
console.log(x); // 10
console.log(currentScope.x); // 10
console.log(parentScope.x); // 10
x = 20;
console.log(x); // 20
console.log(currentScope.x); // 20
console.log(parentScope.x); // 10
}
console.log(x); // 10
console.log(currentScope.x); // 10
console.log(parentScope); // null
}