JSFiddle - React, Tailwind, and code Playground

JavaScript

function inject(func, properties) {
    var args = [], params = [];

    for (var property in properties) {
        if (properties.hasOwnProperty(property)) {
            args.push(properties[property]);
            params.push(property);
        }
    }

    return Function.apply(null, params.concat("return " + func.toString())).apply(null, args);
}

function doSomething(context, callback) {
    var func = inject(callback, context);
    func();
}

doSomething({myVariable: "value"}, function() {
    alert(myVariable);
});