I have the following (simplified) code:
function addOnclickFunction(onclickFunction)
{
var object = document.createElement("img");
object.onclick = function(){eval(onclickFunction)};
return object;
}
i.e. I am passing in a string (onclickFunction) and setting the onclick event for the object equal to whatever the string passed in was.
In terms of whether or not this approach works, then yes, it works in production.
I am however having issues unit testing this properly in QUnit.
QUnit.test("addOnclickFunction should return the an object with onClickproperty", function(assert)
{
var objectTest;
assert.equal(objectTest,undefined);
objectTest = addOnclickFunction("functionCall");
assert.notEqual(objectTest.onclick,null);
assert.equal(objectTest.onclick,"functionCall");
});
In this case the first 2 unit tests will pass. The last one will not as the objectTest.onclick returns
function(){
[code]
}
Is there any way I can make it tell me what the function name is?