"use strict"; var name = "foo"; var customAction = function() { alert("hi there!") } //implement it var func = new Function("action", "return function " + name + "(){ action() };")(customAction); //test it func();