JSFiddle - React, Tailwind, and code Playground
by kassiomaia
JavaScript
var Module = (function() {
var globalContent = {}
function NS(ns) {
return ns
.split('.')
.reduce((current, ns) => (current[ns] = current[ns] || {}, current[ns]), globalContent)
}
window.NS = NS
function define() {
const args = Array.from(arguments)
const fn = args.pop()
const name = args[0]
if (globalContent.hasOwnProperty(name)) {
throw new Error(`This module ${name} is already defined`)
}
args.splice(0, 1)
const modules = args[0].map(ns => NS(ns))
Object.assign(NS(name), fn.apply(this, modules))
}
return {
define,
}
}());
Module.define('Other',
[
'Components.Buttons.Property',
'React',
],
function (Buttons, React) {
console.log(Buttons, React)
return {
test: 10
}
})