0

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 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! :)

3
  • I want to make some things clear, JSON is meant as a data interchange format, what you are using are object literals in javascript and not necessarily JSON. Commented Dec 23, 2010 at 18:14
  • Thanks for the info Quintin! I'am improving my skills developping and I need to learn a lot about this :P Commented Dec 23, 2010 at 18:18
  • @user552669 Absolutely, learning is what it is all about! Commented Dec 23, 2010 at 18:20

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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?

1 Comment

Hi Brian. I want to change the name because this variable is the main JSON object of a plugin that uses to create a context menu. So, I want to change this name if the option was checked or not. Thanks! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.