开发者

Add existing element to Object

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜