JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<div class="hello">w</div>
<div class="hello">o</div>
<div class="hello">r</div>
<div class="hello">l</div>
<div class="hello">d</div>
</div>
JavaScript
function using(args){
var lib = args.lib;
var callback = args.fn;
var global = args.global;
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.contentWindow.exec = function() {
for(var fn in lib){
this[fn] = lib[fn];
}
for(var val in global){
this[val] = global[val];
}
var scr = document.createElement("script");
scr.innerHTML = "("+callback+")()";
iframe.contentWindow.document.body.appendChild(scr);
};
iframe.contentWindow.exec();
for(var val in global){
if(global[val] instanceof Function)
global[val](iframe.contentWindow[val]);
}
iframe.parentNode.removeChild(iframe);
}
var stooges;
var list = document.querySelectorAll(".hello");
using({
lib: _,
global: {
"stooges":function(val){ stooges = val; },
"list":list
},
fn: function(){
function toUpperCase(x){
return x.toUpperCase();
}
function minSize(len){
return function(str){
return str.length >= len;
}
}
stooges = map(filter(["Larry", "Curly", "Moe"], minSize(4)), toUpperCase);
each(list,function(el){console.log(el.innerHTML);});
}
});
console.log(stooges);