I have next object:
开发者_运维问答 var myArray = new Object();
myArray["firstname"] = "Gareth";
myArray["lastname"] = "Simpson";
Also I have function that returns elements (it's value depends from different conditions):
function getNewElement(condition1, ..., conditionN) {
...
return { "my btn": function() { alert(kkk); } }
}
How I can add to myArray
value that returns me getNewElement
function?
myArray["fn"] = getNewElement;
Do you mean
myArray["newElement"] = getNewElement();
or
myArray["my btn"] = getNewElement()["my btn"];
?
Another way to create new Objects
var myObj = {
firstName : "Gareth"
lastName : "Simpson"
};
function getNewElement(condition1, ..., conditionN) {
return { "my btn": function() { alert(kkk); } }
}
myObj.getNewElement;
//to call the function
myObj.getNewElement();
精彩评论