JSFiddle - React, Tailwind, and code Playground
HTML
<div id="status">
</div>
JavaScript
function module()
{
var oauth = {} //I don't want to have to write this to keep it out of the global scope
this.init = function(libraries) {
for (var key in libraries) {
var messy = "if (typeof " + key + " !== 'undefined') {"
messy += key + " = libraries[key] }"
eval(messy)
}
oauth.log('yay!');
}
this.test = function() {
oauth.log(JSON.stringify(oauth))
}
}
function module1() {
this.test = function() {
oauth.log(JSON.stringify(oauth)) //this shouldn't work
}
}
function app()
{
var oauth = {
test : "I should be here",
};
oauth.log = function(input) {
element = document.createTextNode(input)
document.getElementById("status").appendChild(element)
}
var libraries = {
oauth : oauth,
};
var mod = new module();
var mod1 = new module1();
mod.init(libraries);
mod.test();
mod1.test();
}
var app = new app();