Given:
var f1 = function(){return "a";};
var f2 = function(){return "b";};
var f3 = function(){return "c";};
transformToObject([f1, f2, f3]);
How can I create a function:
function transformToObject(arrayOfFuncs){...};
which returns:
{
f1: function(){return "a";},
f2: function(){return "b";},
f3: function(){return "c";}
}
The difficulty seems to get the name of the variable to create a property of the object.
Notice: since I define functions in the form of assignment of anonymous functions to variables, the "name" property of functions won't help because it's empty, which means:
function a(){};
//a.name === "a"
var b = function(){};
//b.name === ""