Skip to content

Instantly share code, notes, and snippets.

@jwerle
Created June 4, 2014 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwerle/2c4f3fdd0ea46dcb48ea to your computer and use it in GitHub Desktop.
Save jwerle/2c4f3fdd0ea46dcb48ea to your computer and use it in GitHub Desktop.
function s (fn, args) {
var code = null;
var f = null;
args = args.map(function (a) {
return 'function' == typeof a ? a.toString() : a;
});
args = JSON.stringify(args);
code = '(' + fn.toString() +').apply(null,'+ args + ')';
f = new Function(code);
return f;
}
function log () {
var a = [].slice.call(arguments);
var f = Function('('+ a.pop() +')()');
console.log.apply(null, a);
f();
}
var p = s(log, ['hi', 'hey', 'hello', function () { console.log('omg'); }]);
p();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment