开发者

Modify javascript object dynamically

I've been developping my web using Javascript and JSON objects. I need to change dynamically the content of my javascript objects, but these are functions.

Example:

var menu1 = [{
   'Activate': function(menuItem,menu) {
      $(this).onSelectStart = "return false";
      var layerclicked = treetag.tree('find',$(this).parent().attr('node-id'));
      if(layerclicked.checked)
         treetag.tree('uncheck',layerclicked.target);
      else
         treetag.tree('check',layerclicked.target);
   }
}];

When the user 开发者_JAVA技巧click an option, I want to change the name function from 'Activate' to 'Deactivate'.

Is can be possible? How could i do?

Thanks in advance! :)


It seems to me that you would benefit from renaming your "Activate" method to "Toggle" instead of renaming the function entirely (seemingly for the purpose of semantics). Renaming your function seems hack-y in my opinion... is it required by the plugin? It would be helpful to know what plugin it is.


Have you tried:

menu1[0].Deactivate = menu1[0].Activate;
menu1[0].Activate = undefined;

What is the purpose of changing the name of the function? Would it make more sense to change what function 'Activate' points to?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜