I am trying to evaluate a function in a new context, ie, one that contains a certain word defined that does not exist in the scope. It is easy enough if I have the definition of the function as a string, but I would like to provide the ability to do this with a regular list of functions, like so:
var funcs = {
first: function() { return 'yayaya'; },
second: function() { return 'okokok' + keyword; },
...
};
then later:
function Thing () {};
for (func in funcs) {
var definition = funcs[func].definition();
var keyword = "NOW I AM THE KEYWORD";
var actual_func_with_keyword_defined = eval(definition);
Thing.prototype[func] = actual_func_with_keyword_defined;
}
What I am missing is the definition() function or equivalent, which returns the source of the function. Is this possible in javascript?