JSFiddle - React, Tailwind, and code Playground

by JAAulde

JavaScript

/* Library builder */
var lib = ( function()
{
    var aLibrary = [],
        oDummyScope = {};

    var libFunc = function( sFuncBody )
    {
        var func = new Function( sFuncBody ),
            index = aLibrary.length;
        
        aLibrary.push( func );

        return index;
    };
    
    libFunc.exec = function( index, args )
    {
        if( typeof aLibrary[index] === 'function' )
        {
            aLibrary[index].apply( oDummyScope, args );
        }
    };

    return libFunc;
}() );

/* Random class using the lib */
var Foo = function( sName )
{
    this.fooName = sName;
};
Foo.prototype.bar = function()
{
    var banana = 'for monkeys';
    alert( banana );

    var libIndex = lib( 'apple = "orange"; banana = "for you!"' );
    lib.exec( libIndex );

    alert( banana );
};

/* Proof of concept */
window.apple = 'apple';
var baz = new Foo( 'My name is baz' );
alert( window.apple );
baz.bar();
alert( window.apple );